You are here

function manualcrop_media_element_after_build in Manual Crop 7

Additional after build callback to modify the Media widget.

1 string reference to 'manualcrop_media_element_after_build'
_manualcrop_media_element_add_after_build in ./manualcrop.helpers.inc
Adds the #after_build entry to a media element.

File

./manualcrop.module, line 369

Code

function manualcrop_media_element_after_build($element) {
  $data = array(
    'manualcrop' => array(
      'entity_type' => $element['#entity_type'],
      'bundle' => $element['#bundle'],
      'field_name' => $element['#field_name'],
    ),
  );

  // Add the options to the element.
  $element['#media_options']['global'] += $data;

  // Update the cached options.
  $element_js_class = drupal_html_class('js-media-element-' . $element['#id']);
  $cid = $element['browse_button']['#attached']['js'][0]['data']['media']['elements']['.' . $element_js_class]['global']['options'];
  cache_set('media_options:' . $cid, $element['#media_options']['global'], 'cache_form', REQUEST_TIME + 21600);

  // Attach the options as javascript settings.
  if (!empty($element['#attached']['js'])) {
    foreach ($element['#attached']['js'] as &$js) {
      if (isset($js['data']['media'])) {
        if (!isset($js['data']['media']['elements']['#' . $element['#id']]['global'])) {
          $js['data']['media']['elements']['#' . $element['#id']]['global'] = array();
        }
        $js['data']['media']['elements']['#' . $element['#id']]['global'] += $data;
        break;
      }
    }
  }

  // Modify the "Edit" link.
  if (!empty($element['edit'])) {
    $element['edit']['#options']['query']['manualcrop'] = $data['manualcrop'];
  }
  return $element;
}