ifthenelse-8.x-1.x-dev-no-core/modules/contrib/if_then_else/src/core/Nodes/Actions/DeleteEntityAction/DeleteEntityAction.php

modules/contrib/if_then_else/src/core/Nodes/Actions/DeleteEntityAction/DeleteEntityAction.php
<?php

namespace Drupal\if_then_else\core\Nodes\Actions\DeleteEntityAction;

use Drupal\Core\Entity\EntityInterface;
use Drupal\if_then_else\core\Nodes\Actions\Action;
use Drupal\if_then_else\Event\NodeSubscriptionEvent;

/**
 * Delete entity action node class.
 */
class DeleteEntityAction extends Action {

  /**
   * {@inheritdoc}
   */
  public static function getName() {
    return 'delete_entity_action';
  }

  /**
   * {@inheritdoc}
   */
  public function registerNode(NodeSubscriptionEvent $event) {
    $event->nodes[static::getName()] = [
      'label' => t('Delete Entity'),
      'type' => 'action',
      'class' => 'Drupal\\if_then_else\\core\\Nodes\\Actions\\DeleteEntityAction\\DeleteEntityAction',
      'inputs' => [
        'entity' => [
          'label' => t('Entity'),
          'description' => t('Entity object.'),
          'sockets' => ['object.entity'],
          'required' => TRUE,
        ],
      ],
    ];
  }

  /**
   * {@inheritDoc}.
   */
  public function process() {
    /** @var \Drupal\Core\Entity\EntityBase $entity */
    $entity = $this->inputs['entity'];

    if (!$entity instanceof EntityInterface) {
      \Drupal::logger('if_then_else')->notice(t("Rule @node_name did not run as the instance of the entity could not be found", ['@node_name' => $this->data->name]));
      $this->setSuccess(FALSE);
      return;
    }
    $entity->delete();

  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc