beautytips-8.x-1.x-dev/includes/textinput.inc
includes/textinput.inc
<?php use Drupal\Core\Url; use Drupal\Core\Link; use Symfony\Component\HttpFoundation\RedirectResponse; function beautytips_textinput_admin_info() { $form['beautytips_text'] = [ '#type' => 'fieldset', '#title' => 'Text Input Tooltips', '#collapsible' => TRUE, '#collapsed' => TRUE, ]; $form['beautytips_text']['beautytips_text_input'] = [ '#type' => 'checkbox', '#title' => 'Display Text input popups', '#default_value' => \Drupal::state()->get('beautytips_text_input', FALSE), ]; $form['beautytips_text']['beautytips_position'] = [ '#type' => 'radios', '#title' => 'Which side should the text popups appear on?', '#options' => [ 'bottom' => t('bottom'), 'top' => t('top'), 'left' => t('left'), 'right' => t('right'), ], '#default_value' => \Drupal::state()->get('beautytips_position', 'bottom'), ]; $form['beautytips_text']['form_id'] = [ '#type' => 'fieldset', '#title' => 'Restrict text popups to specific forms. (OPTIONAL)', '#collapsible' => TRUE, '#collapsed' => TRUE, ]; $form['beautytips_text']['form_id']['beautytips_form_id'] = [ '#type' => 'textfield', '#title' => 'Enter the form id(s) to use for text popup beautytips', '#description' => t('You need to use Drupal php syntax like page_node_form'), '#default_value' => \Drupal::state()->get('beautytips_form_id', ''), ]; $form['beautytips_text']['form_id']['beautytips_show_form'] = [ '#type' => 'checkbox', '#title' => 'Display form_ids', '#description' => t("Turn this on if you want to see the names of the form ids to enter above. The names will appear on the pages where the forms are displayed.") . '<div>' . t("Make sure that you turn it off when you're done retrieving the form_ids.") . '</div>', '#default_value' => \Drupal::state()->get('beautytips_show_form', ''), ]; return $form; } function beautytips_textinput_menu_items() { $items['beautytips/settings/form_ids'] = [ 'page callback' => 'beautytips_textinput_form_id_off', 'access arguments' => ['administer site configuration'], 'file' => 'textinput.inc', 'file path' => drupal_get_path('module', 'beautytips_ui') . '/includes', 'type' => MENU_CALLBACK, ]; return $items; } function beautytips_textinput_form_change(&$form, $form_state, $form_id) { if (\Drupal::state()->get('beautytips_text_input', FALSE)) { if (\Drupal::state()->get('beautytips_show_form', FALSE)) { $url = Url::fromUserInput('/beautytips/settings/form_ids', ['query' => \Drupal::destination()->getAsArray()]); \Drupal::messenger()->addMessage(t("The form_id is %form_id. This message should be @link when finished you're finished checking form_ids.", [ '%form_id' => $form_id, '@link' => Link::fromTextAndUrl(t('turned off'), $url)->toString(), ])); } $add_bt = TRUE; if (strlen(\Drupal::state()->get('beautytips_form_id', ''))) { if (strpos(\Drupal::state()->get('beautytips_form_id', ''), $form_id) === FALSE) { $add_bt = FALSE; } } if ($add_bt) { $options = []; $options['bt_text_field'] = [ 'cssSelect' => 'input.form-text', 'trigger' => ['focus', 'blur'], 'contentSelector' => "$(this).nextAll('.description:eq(0)').hide().html()", 'width' => '275px', 'positions' => [0 => \Drupal::state()->get('beautytips_position', 'bottom')], 'preEval' => TRUE, ]; // Text areas can have format text with description or just a description. // The html structure is different depending on which one is chosen. // It would be nice to have a slightly better way of doing this. $content = " if ($(this).parent('.form-textarea-wrapper').nextAll('.description:eq(0)').length !== 0) { $(this).parent('.form-textarea-wrapper').nextAll('.description:eq(0)').hide().html(); } else if ($(this).parent('.form-textarea-wrapper').parent('.form-item').nextAll('.description:eq(0)').length !== 0) { $(this).parent('.form-textarea-wrapper').parent('.form-item').nextAll('.description:eq(0)').hide().html(); } else { null; }"; $options['bt_text_area'] = [ 'cssSelect' => 'textarea.form-textarea', 'trigger' => ['focus', 'dblclick'], 'contentSelector' => $content, 'width' => '275px', 'positions' => [0 => \Drupal::state()->get('beautytips_position', 'bottom')], 'preEval' => TRUE, ]; beautytips_add_beautytips($options); } } } /** * Menu callback. Turns off the display of form-ids. */ function beautytips_textinput_form_id_off() { \Drupal::state()->set('beautytips_show_form', FALSE); $url = \Drupal::service('redirect.destination')->getAsArray(); $destination = $url ? $url : 'admin/settings/beautytips'; return new RedirectResponse(Url::fromRoute($destination)); }