You are here

function _brightcove_configure_playlist_entity in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove.playlist.inc \_brightcove_configure_playlist_entity()

Create fields on the playlist entity when enabling or upgrading the module.

2 calls to _brightcove_configure_playlist_entity()
brightcove_enable in ./brightcove.module
Implements hook_enable().
brightcove_update_7600 in ./brightcove.install
Update to the 7.x-6.x version.

File

./brightcove.playlist.inc, line 597
Brightcove playlist related functions.

Code

function _brightcove_configure_playlist_entity() {

  // Clear field types from cache
  _field_info_collate_types(TRUE);

  // Add the brightcove_field field type.
  $field_type = 'brightcove_field';
  $field_name = 'brightcove_playlist_videos';
  $entity_type = 'brightcove_playlist';
  $field = field_info_field($field_name);
  $instance = field_info_instance($entity_type, $field_name, BRIGHTCOVE_PLAYLIST_TYPE_MANUAL);
  if (empty($field)) {
    $field = [
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => -1,
      'entity_types' => [
        $entity_type,
      ],
      'translatable' => FALSE,
      'locked' => TRUE,
      'storage' => [
        'type' => 'brightcove_playlist_video_storage',
      ],
    ];
    $field = field_create_field($field);
  }

  // Set field to active via a query because field_update_field() does
  // not work on inactive fields.
  db_update('field_config')
    ->fields([
    'active' => 1,
  ])
    ->condition('field_name', $field_name, '=')
    ->condition('deleted', 0, '=')
    ->execute();
  field_cache_clear();
  if (empty($instance)) {
    $instance = [
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'bundle' => BRIGHTCOVE_PLAYLIST_TYPE_MANUAL,
      'label' => t('Videos'),
      'settings' => [],
      'widget' => [
        'type' => BRIGHTCOVE_VIDEO_WIDGET,
      ],
      'display' => [],
    ];
    field_create_instance($instance);
  }
}