protected function LayoutBuilderEntityViewDisplay::removeSectionField in Drupal 10
Same name and namespace in other branches
- 8 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::removeSectionField()
- 9 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 174
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) {
$query = $this
->entityTypeManager()
->getStorage($this
->getEntityTypeId())
->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();
}
}