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?