ChildOfMicrosite.php in Entity Reference Hierarchy 8.2
File
modules/entity_hierarchy_microsite/src/Plugin/Condition/ChildOfMicrosite.php
View source
<?php
namespace Drupal\entity_hierarchy_microsite\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\entity_hierarchy_microsite\Plugin\MicrositePluginTrait;
use Drupal\node\NodeInterface;
class ChildOfMicrosite extends ConditionPluginBase implements ContainerFactoryPluginInterface {
use MicrositePluginTrait;
public function evaluate() {
if (empty($this->configuration['field'])) {
return TRUE;
}
return ($node = $this
->getContextValue('node')) && $node instanceof NodeInterface && $this->childOfMicrositeLookup
->findMicrositesForNodeAndField($node, $this->configuration['field']);
}
public function summary() {
$options = $this
->getFieldOptions();
if (empty($this->configuration['field'])) {
return '';
}
return $this
->t('@state true if current page is a child of a microsite for the @field field.', [
'@field' => $options[$this->configuration['field']],
'@state' => empty($this->configuration['negate']) ? $this
->t('Return') : $this
->t('Do not return'),
]);
}
}
Classes
Name |
Description |
ChildOfMicrosite |
Defines a condition plugin to test if current page is child of microsite. |