entity.install 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?php

/**
 * @file
 * Install, update and uninstall functions for the entity module.
 */

use Drupal\Component\Uuid\Uuid;

/**
 * Returns the raw configuration object for an EntityDisplay entity.
 *
 * The function returns the existing configuration entry if it exists, or
 * creates a fresh structure.
 *
 * @param string $entity_type
 *   The entity type.
 * @param string $bundle
 *   The bundle name.
 * @param string $view_mode
 *   The view mode.
 *
 * @return \Drupal\Core\Config\Config
 *   The configuration object.
 */
function _update_8000_entity_get_display($entity_type, $bundle, $view_mode) {
  $id = $entity_type . '.' . $bundle . '.' . $view_mode;
  $config = config("entity.display.$id");
  if ($config->get()) {
    return $config;
  }

  // Initialize a fresh structure.
  $uuid = new Uuid();
  $properties = array(
    'id' => $id,
    'uuid' => $uuid->generate(),
    'targetEntityType' => $entity_type,
    'bundle' => $bundle,
    'viewMode' => $view_mode,
    'content' => array(),
  );
  foreach ($properties as $key => $value) {
    $config->set($key, $value);
  }
  return $config;
}