You are here

function paragraphs_update_8002 in Paragraphs 8

Add parent ID, parent type and parent field name fields.

File

./paragraphs.install, line 36
Installation hooks for Paragraphs module.

Code

function paragraphs_update_8002() {
  $storage_definition = BaseFieldDefinition::create('string')
    ->setLabel(t('Parent ID'))
    ->setDescription(t('The ID of the parent entity of which this entity is referenced.'))
    ->setSetting('is_ascii', TRUE);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('parent_id', 'paragraph', 'paragraph', $storage_definition);
  $storage_definition = BaseFieldDefinition::create('string')
    ->setLabel(t('Parent type'))
    ->setDescription(t('The entity parent type to which this entity is referenced.'))
    ->setSetting('is_ascii', TRUE)
    ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('parent_type', 'paragraph', 'paragraph', $storage_definition);
  $storage_definition = BaseFieldDefinition::create('string')
    ->setLabel(t('Parent field name'))
    ->setDescription(t('The entity parent field name to which this entity is referenced.'))
    ->setSetting('is_ascii', TRUE)
    ->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('parent_field_name', 'paragraph', 'paragraph', $storage_definition);
}