Skip to content
Snippets Groups Projects
Commit e4641698 authored by Roderik Muit's avatar Roderik Muit
Browse files

Issue #3446953 by roderik: Fix UI/config bugs in field_* and extra-fields

parent 4da2b1e9
No related branches found
No related tags found
1 merge request!59Resolve #3446953 "Fix uiconfig bugs"
Pipeline #172653 passed
......@@ -195,7 +195,7 @@ class EntityCustomElementsDisplayEditForm extends EntityDisplayFormBase {
*/
protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
$field_name = $field_definition->getName();
$field_name = str_starts_with($field_name, 'field_') ? substr($field_name, strlen('field_')) : $field_name;
$default_name = str_starts_with($field_name, 'field_') ? substr($field_name, strlen('field_')) : $field_name;
$label = $field_definition->getLabel();
$display_options = $this->entity->getComponent($field_name);
......@@ -212,7 +212,7 @@ class EntityCustomElementsDisplayEditForm extends EntityDisplayFormBase {
'#type' => 'textfield',
'#title' => $this->t('Attribute / Slot name'),
'#title_display' => 'invisible',
'#default_value' => $display_options['name'] ?? $field_name,
'#default_value' => $display_options['name'] ?? $default_name,
'#size' => 20,
'#required' => empty($display_options) || $display_options['region'] != 'hidden',
];
......
......@@ -44,6 +44,16 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
*/
protected $displayContext = 'view';
/**
* Whether this display is enabled or not.
*
* If the entity (form) display is disabled, we'll fall back to the 'default'
* display.
*
* @var bool
*/
protected $status = TRUE;
/**
* Custom element name to be displayed.
*
......@@ -172,36 +182,37 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
* {@inheritdoc}
*/
protected function init() {
// Check if any components are present before doing other initialization.
$componentsPresent = !empty($this->content) || !empty($this->hidden);
// Do not call parent::init(); we don't need its display defaults.
if (!$this->targetEntityType) {
return;
}
parent::init();
if (!$this->getCustomElementName()) {
$custom_element = $this->ceGenerator->getViewModeDefaults($this->targetEntityType, $this->bundle, $this->originalMode);
$this->setCustomElementName($custom_element->getPrefixedTag());
}
if ($this->targetEntityType) {
if (!$this->getCustomElementName()) {
$custom_element = $this->ceGenerator->getViewModeDefaults($this->targetEntityType, $this->bundle, $this->originalMode);
$this->setCustomElementName($custom_element->getPrefixedTag());
}
// Check if any components are present before doing other initialization.
$componentsPresent = !empty($this->content) || !empty($this->hidden);
if (!$componentsPresent) {
// Enable components options as done in the regular entity_view_display.
$entity_view_display = \Drupal::service('entity_display.repository')
->getViewDisplay($this->targetEntityType, $this->bundle, $this->originalMode);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
if (!$componentsPresent) {
// Enable components options as done in the regular entity_view_display.
$entity_view_display = \Drupal::service('entity_display.repository')
->getViewDisplay($this->targetEntityType, $this->bundle, $this->originalMode);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
// @todo Add support for statically set values.
// Enable every component with "auto" that is enabled in the display.
foreach ($entity_view_display->getComponents() as $name => $component) {
// Ignore extra-fields.
if (isset($field_definitions[$name])) {
$this->setComponent($name, [
'name' => $name,
'formatter' => 'auto',
'weight' => $component['weight'],
'region' => 'content',
'is_slot' => str_starts_with($field_definitions[$name]->getType(), 'text') ? 1 : 0,
]);
}
// @todo Add support for statically set values.
// Enable every component with "auto" that is enabled in the display.
foreach ($entity_view_display->getComponents() as $name => $component) {
// Ignore extra-fields.
if (isset($field_definitions[$name])) {
$default_name = str_starts_with($name, 'field_') ? substr($name, strlen('field_')) : $name;
$this->setComponent($name, [
'name' => $default_name,
'formatter' => 'auto',
'weight' => $component['weight'],
'region' => 'content',
'is_slot' => str_starts_with($field_definitions[$name]->getType(), 'text') ? 1 : 0,
]);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment