You are here

function dnd_entity_view_alter in Scald: Media Management made easy 7

Implements hook_entity_view_alter().

Adds the dnd library in case we have quickedit enabled and dnd enabled on the entity.

File

modules/library/dnd/dnd.module, line 244

Code

function dnd_entity_view_alter(&$build, $type) {
  if (!module_exists('quickedit')) {
    return;
  }
  if (!user_access('access in-place editing')) {
    return;
  }

  // In-place editing is only supported on the front-end.
  if (path_is_admin(current_path())) {
    return;
  }
  $dnd_enabled = FALSE;
  foreach ($build as $item) {
    if (!is_array($item)) {
      continue;
    }
    if (isset($item['#field_name'])) {
      $instance_info = field_info_instance($type, $item['#field_name'], $build['#bundle']);
      if (!empty($instance_info['settings']['dnd_enabled'])) {
        $dnd_enabled = TRUE;
      }
      if (isset($item['#field_type']) && $item['#field_type'] === 'atom_reference') {
        $dnd_enabled = TRUE;
      }
    }
  }
  if ($dnd_enabled) {
    $build['#attached']['library'][] = array(
      'dnd',
      'library',
    );
  }
  return;
}