public function BehaviorInvoker::getRabbitHoleValuesForEntity in Rabbit Hole 2.x
Same name and namespace in other branches
- 8 src/BehaviorInvoker.php \Drupal\rabbit_hole\BehaviorInvoker::getRabbitHoleValuesForEntity()
An entity's rabbit hole configuration, or the default if it does not exist.
Return an entity's rabbit hole configuration or, failing that, the default configuration for the bundle (which itself will call the base default configuration if necessary).
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to apply rabbit hole behavior on.
Return value
array An array of values from the entity's fields matching the base properties added by rabbit hole.
Overrides BehaviorInvokerInterface::getRabbitHoleValuesForEntity
1 call to BehaviorInvoker::getRabbitHoleValuesForEntity()
- BehaviorInvoker::getBehaviorPlugin in src/
BehaviorInvoker.php - Get the behavior plugin for the given entity.
File
- src/
BehaviorInvoker.php, line 188
Class
- BehaviorInvoker
- Default implementation of Rabbit Hole behaviors invoker.
Namespace
Drupal\rabbit_holeCode
public function getRabbitHoleValuesForEntity(ContentEntityInterface $entity) {
$field_keys = array_keys($this->rhEntityExtender
->getGeneralExtraFields());
$values = [];
$config = $this->rhBehaviorSettingsManager
->loadBehaviorSettingsAsConfig($entity
->getEntityType()
->getBundleEntityType() ?: $entity
->getEntityType()
->id(), $entity
->getEntityType()
->getBundleEntityType() ? $entity
->bundle() : NULL);
// We trigger the default bundle action under the following circumstances:
$trigger_default_bundle_action = !$config
->get('allow_override') || !$entity
->hasField('rh_action') || $entity
->get('rh_action')->value == NULL || $entity
->get('rh_action')->value == 'bundle_default';
if ($trigger_default_bundle_action) {
foreach ($field_keys as $field_key) {
$config_field_key = substr($field_key, 3);
$values[$field_key] = $config
->get($config_field_key);
}
}
else {
foreach ($field_keys as $field_key) {
if ($entity
->hasField($field_key)) {
$values[$field_key] = $entity->{$field_key}->value;
}
}
}
return $values;
}