Changing textfield into textarea

I hope I’m right here with my request and someone can help. I’m working on a website with Drupal, but am not a trained programmer.

I use a module which allows me to display a tooltip in Drupal. By default, this is defined as type “textfield” and therefore has a maximum of 128 characters. As I need more characters, I have changed the “textfield” into “textarea”. As a result, I have more characters available. If I save the tooltip it is recognized and displayed correctly in the frontend. Only when I edit the tooltip again, the entered text is gone.

Here’s the code (the change I made is on line 25):

<?php  /**  * @file  * module for adding a link to a block title tooltip.  */  /**  * Implements hook_form_alter().  */ function block_title_tooltip_form_alter(&$form, &$form_state, $form_id) {   if ($form_id == 'block_admin_configure' || $form_id == 'block_add_block_form') {     $block = new stdClass();     $block->module = $form['module']['#value'];     $block->delta = $form['delta']['#value'];     $title_tooltip_data = block_title_tooltip_get_data($block);     $form['settings']['block_title_tooltip'] = array(       '#type' => 'fieldset',       '#title' => t('Block Title Tooltip Settings'),       '#collapsible' => TRUE,       '#weight' => 0,       '#tree' => TRUE,     );     $form['settings']['block_title_tooltip']['title_tooltip'] = array(       '#type' => 'textarea',       '#title' => t('Title Tooltip'),       '#default_value' => $title_tooltip_data,       '#description' => t('Block Title tooltip.'),     );     if (!isset($form['block_settings']['#weight'])) {       $form['block_settings']['#weight'] = -1;     }     $form['#submit'][] = 'block_title_tooltip_form_submit';   } }  /**  * Implements hook_block_view_alter().  */ function block_title_tooltip_block_view_alter(&$data, $block) {   if (isset($data['content']) && is_array($data['content'])) {     $data['content']['#attached']['css'][] = drupal_get_path('module', 'block_title_tooltip') . '/css/block_title_tooltip.css';   } }  /**  * Implements hook_form_submit().  */ function block_title_tooltip_form_submit($form, &$form_state) {   $block = new stdClass();   $block->module = $form['module']['#value'];   $block->delta = $form_state['values']['delta'];   $title_tooltip = $form_state['values']['block_title_tooltip']['title_tooltip'];   $data = array(     'title_tooltip' => $title_tooltip,   );   if (empty($title_tooltip)) {     block_title_tooltip_delete_data($block);   }   else {     block_title_tooltip_save_data($block, $data);   } }  /**  * Function to delete block data.  *  * @param object $block  *   The block object.  */ function block_title_tooltip_delete_data($block) {   if (!isset($block->module) && !isset($block->delta)) {     return FALSE;   }   $result = db_delete('block_title_tooltip')   ->condition('module', $block->module, '=')   ->condition('delta', $block->delta, '=')   ->execute(); }  /**  * Function to save Block title tooltip data.  *  * @param object $block  *   The block object.  *  * @param array $data  *   Array containing data.  */ function block_title_tooltip_save_data($block, $data) {   if (empty($block->module) || empty($block->delta)) {     return FALSE;   }    // Remove old settings.   $result = db_delete('block_title_tooltip')   ->condition('module', $block->module)   ->condition('delta', $block->delta)   ->execute();    // Save new settings.   $result = db_insert('block_title_tooltip')   ->fields(array(       'module' => $block->module,       'delta' => $block->delta,       'tooltip' => $data,       ))     ->execute();   drupal_set_message(t('Your configuration save.')); }  /**  * Implements hook_preprocess_block().  */ function block_title_tooltip_preprocess_block(&$vars, $hook) {   global $user;   if ($hook == 'block') {     $data = block_title_tooltip_get_data($vars['block']);     if ($data) {       $vars['block']->title_tooltip = (isset($data['tooltip'])) ? $data['tooltip'] : NULL;       $vars['block']->title_tooltip = $vars['block']->title_tooltip;       $display = (isset($data['display'])) ? $data['display'] : TRUE;       if (!empty($vars['block']->title_tooltip) && $display) {         $arbitrary_array = array(           'path' => drupal_get_path('module', 'block_title_tooltip') . '/image/callout.gif',           'attributes' => array('class' => 'block_title_tooltip'),         );         $vars['block']->subject = '<div class="tooltip">' . $vars['block']->subject . '<span>' . theme('image', $arbitrary_array) . check_plain($vars['block']->title_tooltip) . '</span></div>';       }     }   } }  /**  * Function to return the data associated with a block_title_tooltip.  *  * @param object $block  *   object of Block  *  * @return array  *   A renderable array containing display_link and title_tooltip variable.  */ function block_title_tooltip_get_data($block) {   if (!isset($block->module) && !isset($block->delta)) {     return FALSE;   }   $result = db_select('block_title_tooltip', 'btt')   ->condition('btt.module', $block->module, '=')   ->condition('btt.delta', $block->delta, '=')   ->fields('btt', array('tooltip'))   ->execute()   ->fetchAssoc();   if (is_array($result)) {     return $result;   }   else {     return FALSE;   } } 

Can anyone tell me what I have to change so that the tooltip is stored properly. I suspect that under the heading “* Function to save tooltip title block data.” something needs to be adjusted.

I also get this warning (maybe it has to do with it):

Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (Zeile 1573 von C:xampphtdocsdrupal722includesbootstrap.inc).

Perhaps somebody sees the mistake?

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Changing textfield into textarea

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.