Skip to content
Snippets Groups Projects
Commit fde45bdb authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3245321 by jurgenhaas: Implement ConditionalApplianceInterface for all ECA event classes

parent fabb6d9f
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ abstract class ContentEntityBase extends Event implements ConditionalApplianceIn
* {@inheritdoc}
*/
public function applies(string $id, array $arguments): bool {
return $this->bundleFieldApplies($this->getEntity(), $arguments['type']);
return TRUE;
}
}
......@@ -4,13 +4,14 @@ namespace Drupal\eca_content\Event;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\eca\ContentEntityEventInterface;
/**
* Class ContentEntityBaseEntity
*
* @package Drupal\eca_content\Event
*/
abstract class ContentEntityBaseEntity extends ContentEntityBase {
abstract class ContentEntityBaseEntity extends ContentEntityBase implements ContentEntityEventInterface {
/**
* @var \Drupal\Core\Entity\EntityInterface
......@@ -28,7 +29,14 @@ abstract class ContentEntityBaseEntity extends ContentEntityBase {
}
/**
* @return \Drupal\Core\Entity\EntityInterface
* {@inheritdoc}
*/
public function applies(string $id, array $arguments): bool {
return $this->bundleFieldApplies($this->getEntity(), $arguments['type']);
}
/**
* {@inheritdoc}
*/
public function getEntity(): EntityInterface {
return $this->entity;
......
......@@ -5,13 +5,14 @@ namespace Drupal\eca_form\Event;
use Drupal\Component\EventDispatcher\Event;
use Drupal\Core\Form\FormStateInterface;
use Drupal\eca\Event\ConditionalApplianceInterface;
use Drupal\eca\FormEventInterface;
/**
* Class FormBase
*
* @package Drupal\eca_form\Event
*/
abstract class FormBase extends Event implements ConditionalApplianceInterface {
abstract class FormBase extends Event implements ConditionalApplianceInterface, FormEventInterface {
/**
* @var array
......@@ -41,21 +42,21 @@ abstract class FormBase extends Event implements ConditionalApplianceInterface {
}
/**
* @return array
* {@inheritdoc}
*/
public function getForm(): array {
return $this->form;
}
/**
* @param array $form
* {@inheritdoc}
*/
public function setForm(array $form): void {
$this->form = $form;
}
/**
* @return \Drupal\Core\Form\FormStateInterface
* {@inheritdoc}
*/
public function getFormState(): FormStateInterface {
return $this->formState;
......
<?php
namespace Drupal\eca;
use Drupal\Core\Entity\EntityInterface;
/**
* Interface for content entity related events.
*/
interface ContentEntityEventInterface {
/**
* Get the entity which was involved in the entity event.
*
* @return \Drupal\Core\Entity\EntityInterface
*/
public function getEntity(): EntityInterface;
}
......@@ -8,10 +8,10 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Logger\LoggerChannel;
use Drupal\eca\ActionInterface;
use Drupal\eca\ContentEntityEventInterface;
use Drupal\eca\FormEventInterface;
use Drupal\eca\PluginConditionInterface;
use Drupal\eca\Token\TokenInterface;
use Drupal\eca_content\Event\ContentEntityBaseEntity;
use Drupal\eca_form\Event\FormBase;
/**
* A trait for ECA config entities and ECA objects.
......@@ -127,7 +127,7 @@ trait EcaObjectTrait {
}
elseif ($plugin instanceof ActionInterface || $plugin instanceof PluginConditionInterface) {
$event = $plugin->getEvent();
if ($event instanceof ContentEntityBaseEntity && $entity = $event->getEntity()) {
if ($event instanceof ContentEntityEventInterface && $entity = $event->getEntity()) {
$this->token()->addTokenData('entity', $entity);
return $entity;
}
......@@ -151,7 +151,7 @@ trait EcaObjectTrait {
protected function getFormEvent(PluginInspectionInterface $plugin): ?Event {
if ($plugin instanceof ActionInterface || $plugin instanceof PluginConditionInterface) {
$event = $plugin->getEvent();
if ($event instanceof FormBase) {
if ($event instanceof FormEventInterface) {
return $event;
}
}
......
<?php
namespace Drupal\eca;
use Drupal\Core\Form\FormStateInterface;
/**
* Interface for form API related events.
*/
interface FormEventInterface {
/**
* Gets the form array which was involved in the form event.
*
* @return array
*/
public function getForm(): array;
/**
* Sets the form array for this event.
*
* This is needed, if the receiver of the form array had to modify the array
* and needs to hand over the changes to the subsequent process.
*
* @todo: Analyse if we could change getForm() into a method that returns
* the form array by reference.
*
* @param array $form
*/
public function setForm(array $form): void;
/**
* Gets the form state object which was involved in the form event.
*
* @return \Drupal\Core\Form\FormStateInterface
*/
public function getFormState(): FormStateInterface;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment