You are here

function copyprevention_page_attachments in Copy Prevention 8

Implements hook_page_attachments().

File

./copyprevention.module, line 49
Main file for Copy Prevention module.

Code

function copyprevention_page_attachments(&$page) {
  global $base_url;
  $copyprevention_images_search = array_filter(\Drupal::configFactory()
    ->getEditable('copyprevention.settings')
    ->get('copyprevention_images_search'));
  if (array_key_exists('httpheader', $copyprevention_images_search)) {
    $page['#attached']['http_header'][] = [
      'X-Robots-Tag',
      'noimageindex',
      TRUE,
    ];
  }
  if (array_key_exists('pagehead', $copyprevention_images_search)) {
    $data = [
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'robots',
        'content' => 'noimageindex',
      ],
    ];
    $page['#attached']['html_head'][] = [
      $data,
      'copyprevention_images_search',
    ];
  }
  if (!_copyprevention_is_enabled()) {
    return;
  }
  $path = $base_url . '/' . drupal_get_path('module', 'copyprevention');
  $settings = [
    'body' => array_filter(\Drupal::configFactory()
      ->getEditable('copyprevention.settings')
      ->get('copyprevention_body')),
    'images' => array_filter(\Drupal::configFactory()
      ->getEditable('copyprevention.settings')
      ->get('copyprevention_images')),
    'images_min_dimension' => \Drupal::configFactory()
      ->getEditable('copyprevention.settings')
      ->get('copyprevention_images_min_dimension'),
    'transparentgif' => file_create_url($path . '/transparent.gif'),
  ];
  $page['#attached']['drupalSettings']['copyprevention'] = $settings;
  $page['#attached']['library'][] = 'copyprevention/copyprevention';
}