You are here

function scald_entity_info in Scald: Media Management made easy 7

Implements hook_entity_info().

Define a new entity type for the Atoms.

File

./scald.module, line 1740
The Scald Core, which handles all Scald Registries and dispatch.

Code

function scald_entity_info() {
  $translatable_field = array(
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => TRUE,
  );
  $translatable_field_instance = array(
    'required' => TRUE,
    'settings' => array(
      'text_processing' => 0,
    ),
    'widget' => array(
      'weight' => -5,
    ),
    'display' => array(
      'default' => array(
        'type' => 'hidden',
      ),
    ),
  );
  $return = array(
    'scald_atom' => array(
      'label' => t('Atoms'),
      'controller class' => 'ScaldAtomController',
      'base table' => 'scald_atoms',
      'uri callback' => 'scald_atom_uri',
      'access callback' => 'scald_atom_access',
      'fieldable' => TRUE,
      'entity keys' => array(
        'id' => 'sid',
        'bundle' => 'type',
        'label' => 'title',
        'language' => 'language',
      ),
      'bundle keys' => array(
        'bundle' => 'type',
      ),
      'bundles' => array(),
      'view modes' => array(),
      'view callback' => 'scald_render_multiple',
      'creation callback' => 'entity_metadata_create_object',
      'deletion callback' => 'scald_atom_delete',
      'save callback' => 'scald_atom_save',
      'translation' => array(
        'entity_translation' => array(
          'class' => 'EntityTranslationScaldHandler',
          'base path' => 'atom/%scald_atom',
          'edit path' => 'atom/%scald_atom/edit/%ctools_js',
          'edit form' => 'atom',
        ),
      ),
      'field replacement' => array(
        'title' => array(
          'field' => $translatable_field,
          'instance' => array(
            'label' => t('Title'),
            'description' => '',
          ) + $translatable_field_instance,
        ),
      ),
      'efq bundle conditions' => TRUE,
    ),
  );
  $contexts = scald_contexts();
  foreach ($contexts as $slug => $context) {

    // Only normal contexts created via Scald UI are rendered with fields. Other
    // contexts are rendered specially and it does not make sense to expose them
    // as view mode to customize field rendering.
    // If a 3rd module defines a new context and would like to expose it as
    // a view mode, it can use hook_entity_info_alter().
    if ($context['provider'] !== 'scald' || isset($context['hidden']) && $context['hidden']) {
      continue;
    }
    $return['scald_atom']['view modes'][$slug] = array(
      'label' => $context['title'],
      'custom settings' => FALSE,
    );
  }
  $types = scald_types();
  foreach ($types as $type => $info) {
    $return['scald_atom']['bundles'][$type] = array(
      'label' => $info->title,
      'admin' => array(
        'path' => 'admin/structure/scald/%scald_type',
        'bundle argument' => 3,
        'real path' => 'admin/structure/scald/' . $type,
        'access arguments' => array(
          'administer scald',
        ),
      ),
    );
  }
  return $return;
}