protected function EntityDisplayBase::init in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/EntityDisplayBase.php \Drupal\Core\Entity\EntityDisplayBase::init()
Initializes the display.
This fills in default options for components:
- that are not explicitly known as either "visible" or "hidden" in the display,
- or that are not supposed to be configurable.
1 call to EntityDisplayBase::init()
- EntityDisplayBase::__construct in core/
lib/ Drupal/ Core/ Entity/ EntityDisplayBase.php - Constructs an Entity object.
File
- core/
lib/ Drupal/ Core/ Entity/ EntityDisplayBase.php, line 159 - Contains \Drupal\Core\Entity\EntityDisplayBase.
Class
- EntityDisplayBase
- Provides a common base class for entity view and form displays.
Namespace
Drupal\Core\EntityCode
protected function init() {
// Only populate defaults for "official" view modes and form modes.
if ($this->mode !== static::CUSTOM_MODE) {
// Fill in defaults for extra fields.
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
$extra_fields = \Drupal::entityManager()
->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array();
foreach ($extra_fields as $name => $definition) {
if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
// Extra fields are visible by default unless they explicitly say so.
if (!isset($definition['visible']) || $definition['visible'] == TRUE) {
$this->content[$name] = array(
'weight' => $definition['weight'],
);
}
else {
$this->hidden[$name] = TRUE;
}
}
}
// Fill in defaults for fields.
$fields = $this
->getFieldDefinitions();
foreach ($fields as $name => $definition) {
if (!$definition
->isDisplayConfigurable($this->displayContext) || !isset($this->content[$name]) && !isset($this->hidden[$name])) {
$options = $definition
->getDisplayOptions($this->displayContext);
if (!empty($options['type']) && $options['type'] == 'hidden') {
$this->hidden[$name] = TRUE;
}
elseif ($options) {
$this->content[$name] = $this->pluginManager
->prepareConfiguration($definition
->getType(), $options);
}
// Note: (base) fields that do not specify display options are not
// tracked in the display at all, in order to avoid cluttering the
// configuration that gets saved back.
}
}
}
}