Commit 4c07ea0c authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #3285668 by Anybody: Add Media-Type/Type-Icons to the Media Library...

Issue #3285668 by Anybody: Add Media-Type/Type-Icons to the Media Library Widget Display [Configuration Update]
parent 1fff0c42
Loading
Loading
Loading
Loading
+99 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Install, update and uninstall functions for the DROWL Media Types module.
 */

/**
 * Add bundle field to media_library widget display.
 */
function drowl_media_types_update_8300(&$sandbox) {
  // For existing sites we
  $view = \Drupal::entityTypeManager()->getStorage('view')->load('media_library');
  if (!empty($view)) {
    $viewWidgetDisplay =& $view->storage->getDisplay('widget');
    if (empty($viewWidgetDisplay['display_options']['fields']['bundle'])) {
      // Definition of the new bundle field:
      $bundleField = [
        'bundle' => [
          'id' => 'bundle',
          'table' => 'media_field_data',
          'field' => 'bundle',
          'relationship' => 'none',
          'group_type' => 'group',
          'admin_label' => '',
          'entity_type' => 'media',
          'entity_field' => 'bundle',
          'plugin_id' => 'field',
          'label' => '',
          'exclude' => false,
          'alter' => [
            'alter_text' => false,
            'text' => '',
            'make_link' => false,
            'path' => '',
            'absolute' => false,
            'external' => false,
            'replace_spaces' => false,
            'path_case' => 'none',
            'trim_whitespace' => false,
            'alt' => '',
            'rel' => '',
            'link_class' => '',
            'prefix' => '',
            'suffix' => '',
            'target' => '',
            'nl2br' => false,
            'max_length' => 0,
            'word_boundary' => true,
            'ellipsis' => true,
            'more_link' => false,
            'more_link_text' => '',
            'more_link_path' => '',
            'strip_tags' => false,
            'trim' => false,
            'preserve_tags' => '',
            'html' => false,
          ],
          'element_type' => '',
          'element_class' => '',
          'element_label_type' => '',
          'element_label_class' => '',
          'element_label_colon' => false,
          'element_wrapper_type' => '',
          'element_wrapper_class' => '',
          'element_default_classes' => true,
          'empty' => '',
          'hide_empty' => false,
          'empty_zero' => false,
          'hide_alter_empty' => true,
          'click_sort_column' => 'target_id',
          'type' => 'entity_reference_label',
          'settings' => [
            'link' => false,
          ],
          'group_column' => 'target_id',
          'group_columns' => [
          ],
          'group_rows' => true,
          'delta_limit' => 0,
          'delta_offset' => 0,
          'delta_reversed' => false,
          'delta_first_last' => false,
          'multi_type' => 'separator',
          'separator' => ', ',
          'field_api_classes' => false,
        ],
      ];
      array_unshift($viewWidgetDisplay['display_options']['fields'], $bundleField);
      $view->storage->save();

      return 'Added "bundle" field successfully to view "media_library" > "widget" display.';
    } else {
      return 'Adding "bundle" field to view "media_library" > "widget" display was skipped as the field already exists there.';
    }
  } else {
    return 'Adding "bundle" field to view media_library "widget" display FAILED. View "media_library" could not be found.';
  }
}