ezcontent-8.x-dev/modules/ezcontent_node/modules/ezcontent_article/ezcontent_article.install
modules/ezcontent_node/modules/ezcontent_article/ezcontent_article.install
<?php
/**
* @file
* Install file for module EzContent Article.
*/
use Drupal\Component\Serialization\Yaml;
/**
* Enhanced the content field display in article form.
*/
function ezcontent_article_update_8001() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper->executeUpdate('ezcontent_article', 'ezcontent_article_update_8001');
// Output logged messages to related channel of update execution.
return $updateHelper->logger()->output();
}
/**
* Configuration update.
*/
function ezcontent_article_update_8002() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper->executeUpdate('ezcontent_article', 'ezcontent_article_update_8002');
// Output logged messages to related channel of update execution.
return $updateHelper->logger()->output();
}
/**
* Configuration update.
*/
function ezcontent_article_update_8003() {
$module_path = \Drupal::service('extension.list.module')->getPath('ezcontent_article');
// Install entityqueue module.
\Drupal::service('module_installer')->install(['entityqueue'], TRUE);
$file = 'entityqueue.entity_queue.featured_articles';
$config_path = $module_path . '/config/install/' . $file . '.yml';
$updated = [];
$created = [];
/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = \Drupal::service('config.manager');
$raw = file_get_contents($config_path);
$value = Yaml::decode($raw);
if (!is_array($value)) {
throw new \RuntimeException(sprintf('Invalid YAML file %s'), $file);
}
$type = $config_manager->getEntityTypeIdByName(basename($file));
$entity_manager = $config_manager->getEntityTypeManager();
$definition = $entity_manager->getDefinition($type);
$id_key = $definition->getKey('id');
$id = $value[$id_key];
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $entity_storage */
$entity_storage = $entity_manager->getStorage($type);
$entity = $entity_storage->load($id);
if ($entity) {
$entity = $entity_storage->updateFromStorageRecord($entity, $value);
$entity->save();
$updated[] = $id;
}
else {
$entity = $entity_storage->createFromStorageRecord($value);
$entity->save();
$created[] = $id;
}
return [
'udpated' => $updated,
'created' => $created,
];
}
