You are here

addtocopy.module in Add link to copied text 8

Same filename and directory in other branches
  1. 6 addtocopy.module
  2. 7 addtocopy.module

Module file for addtocopy.

File

addtocopy.module
View source
<?php

/**
 * @file
 * Module file for addtocopy.
 */

/**
 * Implements hook_page_attachments().
 *
 * Adds the addtocopy library to the page for any user who do not have
 * 'bypass addtocopy' permission.
 */
function addtocopy_page_attachments(array &$page) {

  // Return if user has 'bypass addtocopy' permission.
  if (\Drupal::currentUser()
    ->hasPermission('bypass addtocopy')) {
    return;
  }
  $selector = \Drupal::config('addtocopy.settings')
    ->get('addtocopy.selector') ? \Drupal::config('addtocopy.settings')
    ->get('addtocopy.selector') : '#content';
  $minlen = \Drupal::config('addtocopy.settings')
    ->get('addtocopy.minlen') ? \Drupal::config('addtocopy.settings')
    ->get('addtocopy.minlen') : '25';
  $htmlcopytxt = \Drupal::config('addtocopy.settings')
    ->get('addtocopy.htmlcopytxt') ? \Drupal::config('addtocopy.settings')
    ->get('addtocopy.htmlcopytxt') : '<br>More: <a href="[link]">[link]</a><br>';
  $addcopyfirst = \Drupal::config('addtocopy.settings')
    ->get('addtocopy.addcopyfirst') ? \Drupal::config('addtocopy.settings')
    ->get('addtocopy.addcopyfirst') : '000';
  $page['#attached']['library'][] = 'addtocopy/addtocopy';
  $page['#attached']['drupalSettings']['addtocopy']['addtocopy']['selector'] = $selector;
  $page['#attached']['drupalSettings']['addtocopy']['addtocopy']['minlen'] = $minlen;
  $page['#attached']['drupalSettings']['addtocopy']['addtocopy']['htmlcopytxt'] = $htmlcopytxt;
  $page['#attached']['drupalSettings']['addtocopy']['addtocopy']['addcopyfirst'] = $addcopyfirst;
}

Functions