You are here

function picture_page_build in Picture 7

Same name and namespace in other branches
  1. 7.2 picture.module \picture_page_build()

Implements hook_page_build().

Add the image processing javascript to every page. This allows these scripts to get included in aggregation, which is probably good since there will be pictures needing this javascript on most pages. The library does not get added twice, even if it's attached to multiple fields that are also being displayed with responsive images. Maybe this should check that the page is not an admin theme page?

File

./picture.module, line 1303
Picture formatter.

Code

function picture_page_build(&$page) {
  drupal_add_library('picture', 'matchmedia', TRUE);
  drupal_add_library('picture', 'picturefill', TRUE);
  drupal_add_library('picture', 'picture.ajax', TRUE);

  // Integrate with the WYSIWYG module, and the CKEditor module.
  $picture_groups = picture_get_mapping_options();
  $ckeditor_groups = variable_get('picture_ckeditor_groups', array());
  $groups = array();

  // CKEditor library expects an array of options formatted as
  // ['Display name', 'machine_name'].
  foreach ($ckeditor_groups as $machine_name => $parameters) {
    if (array_key_exists($machine_name, $picture_groups)) {
      if ($parameters['enabled'] == 1) {
        $groups[] = array(
          $picture_groups[$machine_name],
          $machine_name,
        );
      }
    }
  }
  if (!empty($groups)) {
    $groups[] = array(
      'Not Set',
      'not_set',
    );
    drupal_add_js(array(
      'picture' => array(
        'groups' => $groups,
        'label' => variable_get('picture_ckeditor_label', 'Image size (required)'),
      ),
    ), 'setting');
  }
}