You are here

function opigno_module_update_8007 in Opigno module 8

Create new media image field in opigno_module entity.

File

./opigno_module.install, line 548
Opigno module app install/update functionality.

Code

function opigno_module_update_8007() {

  // Create a new field definition.
  $field = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Image'))
    ->setDescription(t('Set here a module image'))
    ->setRevisionable(TRUE)
    ->setTranslatable(FALSE)
    ->setRequired(FALSE)
    ->setSetting('target_type', 'media')
    ->setSetting('handler', 'default')
    ->setSetting('handler_settings', [
    'target_bundles' => [
      'image',
    ],
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'media_thumbnail',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'entity_browser_entity_reference',
    'weight' => 26,
    'settings' => [
      'entity_browser' => 'media_entity_browser_groups',
      'field_widget_display' => 'rendered_entity',
      'field_widget_remove' => TRUE,
      'open' => TRUE,
      'selection_mode' => 'selection_append',
      'field_widget_display_settings' => [
        'view_mode' => 'image_only',
      ],
      'field_widget_edit' => FALSE,
      'field_widget_replace' => FALSE,
      'third_party_settings' => [
        'type' => 'entity_browser_entity_reference',
      ],
    ],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);

  // Install the new definition.
  $definition_manager = \Drupal::entityDefinitionUpdateManager();
  $definition_manager
    ->installFieldStorageDefinition('module_media_image', 'opigno_module', 'opigno_module', $field);
}