custom_pub.install in Custom Publishing Options 8
Same filename and directory in other branches
Install and update function for Custom Publishing Options.
File
custom_pub.installView source
<?php
/**
* @file
* Install and update function for Custom Publishing Options.
*/
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\Entity\BaseFieldOverride;
/**
* Implements hook_uninstall().
* Delete all custom publish option config entities.
*/
function custom_pub_uninstall() {
foreach (\Drupal::entityTypeManager()
->getStorage('custom_publishing_option')
->loadMultiple() as $machine_name => $entity) {
$entity
->delete();
}
}
/**
* Function to add public options under the promotion options.
*/
function custom_pub_update_8091() {
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$update_manager = Drupal::service('entity.definition_update_manager');
$promotion_options = BaseFieldDefinition::create('boolean')
->setLabel(t('Publish under Promotion options'))
->setDescription(t('Under Promotion options'))
->setDefaultValue(FALSE)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'boolean',
'weight' => 5,
])
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'weight' => 5,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$update_manager
->installFieldStorageDefinition('publish_under_promote_options', 'custom_publishing_option', 'custom_pub', $promotion_options);
}
/**
* Update to add new config dependency.
*/
function custom_pub_update_8092() {
$entities = BaseFieldOverride::loadMultiple();
foreach ($entities as $machine_name => $entity) {
$custom_pub_entity = \Drupal::entityTypeManager()
->getStorage('custom_publishing_option')
->load($entity
->getName());
if ($custom_pub_entity) {
$dependencies = $entity
->get('dependencies');
$dependencies['config'][] = $custom_pub_entity
->getConfigDependencyName();
$entity
->set('dependencies', $dependencies);
$entity
->save();
}
}
}
Functions
Name | Description |
---|---|
custom_pub_uninstall | Implements hook_uninstall(). Delete all custom publish option config entities. |
custom_pub_update_8091 | Function to add public options under the promotion options. |
custom_pub_update_8092 | Update to add new config dependency. |