You are here

function baguettebox_field_formatter_view in baguetteBox.js 7

Implements hook_field_formatter_view().

File

./baguettebox.module, line 121
Primary hooks for baguettebox module.

Code

function baguettebox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $settings = $display['settings'];
  $element = array(
    '#theme_wrappers' => array(
      'container',
    ),
    '#attributes' => array(
      'class' => array(
        'baguettebox-container',
      ),
    ),
    '#attached' => array(
      'library' => array(
        array(
          'baguettebox',
          'baguettebox',
        ),
      ),
      'js' => array(
        drupal_get_path('module', 'baguettebox') . '/baguettebox.js',
        array(
          'data' => array(
            'baguettebox' => $settings,
          ),
          'type' => 'setting',
        ),
      ),
    ),
  );
  foreach ($items as $delta => $item) {
    $path = $settings['baguettebox_image_style'] ? image_style_url($settings['baguettebox_image_style'], $item['uri']) : file_create_url($item['uri']);
    $element[$delta] = array(
      '#theme' => 'baguettebox_formatter',
      '#item' => $item,
      '#image_style' => $display['settings']['initial_image_style'],
      '#path' => $path,
    );
  }
  return $element;
}