entity_generic-8.x-3.x-dev/src/Plugin/Action/EnableAction.php

src/Plugin/Action/EnableAction.php
<?php

namespace Drupal\entity_generic\Plugin\Action;

use Drupal\Core\Action\Plugin\Action\EntityActionBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\entity_generic\Generic\EntityStatusInterface;

/**
 * @Action(
 *   id = "entity:enable_action",
 *   label = @Translation("Enable entity"),
 *   deriver = "Drupal\entity_generic\Plugin\Action\Derivative\EnableActionDeriver",
 * )
 */
class EnableAction extends EntityActionBase {

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL) {
    $entity->setStatus(EntityStatusInterface::ENTITY_ENABLED);
    $entity->save();
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    $result = $object->access('update', $account, TRUE)
      ->andIf($object->status->access('edit', $account, TRUE));

    return $return_as_object ? $result : $result->isAllowed();
  }

}

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

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