drowl_paragraphs-8.x-3.9/modules/drowl_paragraphs_container2layout/src/Plugin/Action/ContainerParagraphs2LayoutParagraphsAction.php
modules/drowl_paragraphs_container2layout/src/Plugin/Action/ContainerParagraphs2LayoutParagraphsAction.php
<?php
namespace Drupal\drowl_paragraphs_container2layout\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Action\Plugin\Action\EntityActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
/**
* Container Paragraphs to Layout Paragraphs action.
*
* @Action(
* id = "container_paragraphs2layout_paragraphs_action",
* label = @Translation("DROWL Paragraphs: Container Paragraphs to Layout Paragraphs action"),
* category = @Translation("DROWL Paragraphs"),
* type = "node",
* context = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity"),
* description = @Translation("Any (fieldable) entity")
* ),
* }
* )
*/
class ContainerParagraphs2LayoutParagraphsAction extends EntityActionBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
\Drupal::service('drowl_paragraphs_container2layout.paragraphs_converter')->convertFromParentEntity($entity);
}
/**
* {@inheritDoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
// $result = $object->access('update', $account, TRUE);
$result = AccessResult::allowedIfHasPermission($account, 'drowl_paragraphs_container2layout convert');
return $return_as_object ? $result : $result->isAllowed();
}
}
