collection-8.x-1.x-dev/collection.install
collection.install
<?php
/**
* @file
* Installation hooks for the Collection module.
*/
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Add weight field.
*/
function collection_update_8001() {
$field_storage_definition = BaseFieldDefinition::create('integer')
->setLabel(t('Weight'))
->setSetting('unsigned', FALSE)
->setSetting('size', 'normal')
->setInitialValue(0)
->setDefaultValue(0);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('weight', 'collection_item', 'collection_item', $field_storage_definition);
}
/**
* Add canonical field to collection items.
*/
function collection_update_8002() {
$field_storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Canonical'))
->setInitialValue(TRUE)
->setDefaultValue(FALSE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('canonical', 'collection_item', 'collection_item', $field_storage_definition);
}
/**
* Update the length of the collection_item name field.
*/
function collection_update_8003(&$sandbox) {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Uninstall the field.
$field_storage_definition = $definition_update_manager->getFieldStorageDefinition('name', 'collection_item');
$definition_update_manager->uninstallFieldStorageDefinition($field_storage_definition);
// Create a new field definition.
$new_name_field = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the collection item. This is autogenerated and is for admin use only.'))
->setSettings([
'max_length' => 255,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -4,
])
->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
// Install the new definition.
$definition_update_manager->installFieldStorageDefinition('name', 'collection_item', 'collection_item', $new_name_field);
return t('Collection item name field can now hold longer values.');
}
/**
* Add collectible field to collections.
*/
function collection_update_9001() {
$field_storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Collectible'))
->setDescription(t('If checked, this collection can be added to other collections.'))
->setDefaultValue(FALSE)
->setInitialValue(FALSE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('collectible', 'collection', 'collection', $field_storage_definition);
}
