Module Description
Overview The Clipboard.js module provides integration with the clipboard.js library, which allows non-flash based clipboard copying using the HTML5 Clipboard API.
Drupal 8
The Drupal 8 version of the module provides a field formatter for email, link, string and string_long fields.
Available are the Clipboard.js Button, the Clipboard.js Snippet, the Clipboard.js Textarea and the well-known Clipboard.js Textfield formatter.
Manual or developer usage like described for the Drupal 7 version is still possible, just slightly changed:
$form['copy_this'] = [ '#theme' => 'clipboardjs_textfield', '#title' => $this->t('Clipboard.js Textfield'), '#value' => 'Any copyable value.', '#label' => $this->t('Click to copy'), '#alert_style' => 'tooltip', // e.g., 'tooltip', 'alert' or 'none' '#alert_text' => $this->t('Copied!'), ]; Requirements
* clipboard.js library
* ext-zip
Drupal 7
Requirements
* clipboard.js library
* Libraries 2.x
* jQuery Update (jQuery >= 1.7)
Usage The Clipboard.js can be added to any text field by visiting the manage display 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. Just use the theme function to build the render array:
function example_form($form, $form_state) { $form = array(); // Load clipboard.js library. libraries_load('clipboard'); // Build the form or render element using the theme function. $form['copy_this'] = theme('clipboardjs', array( 'text' => t('This is the text to be copied...'), 'alert_style' => 'tooltip', 'alert_text' => 'Copy was successful!', 'button_label' => 'Click to Copy', )); return $form; } πΊπ¦ #StandWithUkraine Please consider supporting Ukraine in a fight for their freedom and safety of Europe.
Drupal 8
The Drupal 8 version of the module provides a field formatter for email, link, string and string_long fields.
Available are the Clipboard.js Button, the Clipboard.js Snippet, the Clipboard.js Textarea and the well-known Clipboard.js Textfield formatter.
Manual or developer usage like described for the Drupal 7 version is still possible, just slightly changed:
$form['copy_this'] = [ '#theme' => 'clipboardjs_textfield', '#title' => $this->t('Clipboard.js Textfield'), '#value' => 'Any copyable value.', '#label' => $this->t('Click to copy'), '#alert_style' => 'tooltip', // e.g., 'tooltip', 'alert' or 'none' '#alert_text' => $this->t('Copied!'), ]; Requirements
* clipboard.js library
* ext-zip
Drupal 7
Requirements
* clipboard.js library
* Libraries 2.x
* jQuery Update (jQuery >= 1.7)
Usage The Clipboard.js can be added to any text field by visiting the manage display 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. Just use the theme function to build the render array:
function example_form($form, $form_state) { $form = array(); // Load clipboard.js library. libraries_load('clipboard'); // Build the form or render element using the theme function. $form['copy_this'] = theme('clipboardjs', array( 'text' => t('This is the text to be copied...'), 'alert_style' => 'tooltip', 'alert_text' => 'Copy was successful!', 'button_label' => 'Click to Copy', )); return $form; } πΊπ¦ #StandWithUkraine Please consider supporting Ukraine in a fight for their freedom and safety of Europe.
Module Link
Project Usage
6025
Security Covered
Covered By Security Advisory
Version Available
Production
Module Summary
The Clipboard.js module aims to provide integration with the clipboard.js library for non-flash based clipboard copying using the HTML5 Clipboard API in Drupal 8 and Drupal 7 versions.
Data Name
clipboardjs