Unverified Commit dcf247f5 authored by Stefan Auditor's avatar Stefan Auditor
Browse files

Issue #3273105: Fix label and title and update usage example

parent 76d44529
Loading
Loading
Loading
Loading
+14 −21
Original line number Diff line number Diff line
@@ -21,27 +21,20 @@ page for the entity and and choosing Clipboard.js as the field formatter.
Custom text fields can also use clipboard.js using the form api or in a render
array using the theme function to display the element:

    function example_form($form, $form_state) {
      $form = array();


      // Load clipboard.js library.
      libraries_load('clipboard');


      // Clipboard settings.
      $theme_variables = array(
        'text' => t('This is the text to be copied...'),
        'alert_style' => 'tooltip',
        'alert_text' => 'Copy was successful!',
        'button_label' => 'Click to Copy',
      );


      // Build the form or render element using the helper function:
      $form['textfield'] = theme('clipboardjs', $theme_variables);


    public function buildForm(array $form, FormStateInterface $form_state) {
      $form['clipboardjs'] = [
        '#type' => 'textfield',
        '#theme' => 'clipboardjs',
        '#text' => 'The text to copy to clipboard',
        '#alert_text' => $this->t('Copy was successful!'),
        '#alert_style' => 'tooltip',
        '#label' => $this->t('Click to Copy'),
        '#attached' => [
          'library' => [
            'clipboardjs/drupal'
          ],
        ]
      ];
      return $form;
    }

+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ function clipboardjs_theme($existing, $type, $theme, $path) {
        'text' => NULL,
        'alert_style' => 'tooltip',
        'alert_text' => t('Copy was successful!'),
        'label' => t('Click to Copy'),
        'height' => 13,
        'width' => 13,
      ],
+18 −1
Original line number Diff line number Diff line
{#
/**
 * @file
 * Default theme implementation to present a clipboard.js button.
 *
 * Available variables:
 * - text: The value to copy to the clipboard.
 * - alert_style: The alert style e.g., tooltip, alert
 * - alert_text: The alert text.
 * - height: The button height.
 * - width: The button width.
 *
 * @see clipboardjs_preprocess_clipboardjs()
 *
 * @ingroup themeable
 */
#}
{{ attach_library('clipboardjs/drupal') }}
<input id="{{ id }}" type="text" class="clipboardjs" value="{{ text }}" readonly="readonly" /><a class="clipboardjs-button" data-clipboard-alert="{{ alert_style }}" data-clipboard-alert-text="{{ alert_text }}" data-clipboard-target="#{{ id }}">
  <img src="{{ module_path }}/images/clippy.svg" alt="{{ label }}" height="{{ height }}" width="{{ width }}" />
  <img src="{{ module_path }}/images/clippy.svg" alt="{{ label }}" title="{{ label }}" height="{{ height }}" width="{{ width }}" />
</a>