function LayoutBuilderEntityViewDisplay::removeSectionField
Same name in other branches
- 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::removeSectionField()
- 8.9.x core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::removeSectionField()
- 11.x core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::removeSectionField()
Removes a layout section field if it is no longer needed.
Because the field is shared across all view modes, the field will only be removed if no other view modes are using it.
Parameters
string $entity_type_id: The entity type ID.
string $bundle: The bundle.
string $field_name: The name for the layout section field.
1 call to LayoutBuilderEntityViewDisplay::removeSectionField()
- LayoutBuilderEntityViewDisplay::preSave in core/
modules/ layout_builder/ src/ Entity/ LayoutBuilderEntityViewDisplay.php - Acts on an entity before the presave hook is invoked.
File
-
core/
modules/ layout_builder/ src/ Entity/ LayoutBuilderEntityViewDisplay.php, line 188
Class
- LayoutBuilderEntityViewDisplay
- Provides an entity view display entity that has a layout.
Namespace
Drupal\layout_builder\EntityCode
protected function removeSectionField($entity_type_id, $bundle, $field_name) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
$storage = $this->entityTypeManager()
->getStorage($this->getEntityTypeId());
$query = $storage->getQuery()
->condition('targetEntityType', $this->getTargetEntityTypeId())
->condition('bundle', $this->getTargetBundle())
->condition('mode', $this->getMode(), '<>')
->condition('third_party_settings.layout_builder.allow_custom', TRUE);
$enabled = (bool) $query->count()
->execute();
if (!$enabled && ($field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name))) {
$field->delete();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.