Commit 7baf7021 authored by Marcin Grabias's avatar Marcin Grabias
Browse files

Added messages test for V2, applied standards and type hinting.

parent 7a0d5e75
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
namespace Drupal\actions_permissions;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Create permissions for existing actions.
@@ -18,16 +18,14 @@ class ActionsPermissions implements ContainerInjectionInterface {
  /**
   * VBO Action manager service.
   *
   * @var \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
   */
  protected $actionManager;
  protected ViewsBulkOperationsActionManager $actionManager;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;
  protected EntityTypeManagerInterface $entityTypeManager;

  /**
   * Constructor.
@@ -58,7 +56,7 @@ class ActionsPermissions implements ContainerInjectionInterface {
   * @return array
   *   Permissions array.
   */
  public function permissions() {
  public function permissions(): array {
    $permissions = [];
    $entity_type_definitions = $this->entityTypeManager->getDefinitions();

+3 −3
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace Drupal\actions_permissions\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Component\EventDispatcher\Event;
use Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Defines module event subscriber class.
@@ -23,7 +23,7 @@ class ActionsPermissionsEventSubscriber implements EventSubscriberInterface {
  public static function getSubscribedEvents() {
    $events[ViewsBulkOperationsActionManager::ALTER_ACTIONS_EVENT][] = [
      'alterActions',
      static::PRIORITY,
      self::PRIORITY,
    ];
    return $events;
  }
@@ -34,7 +34,7 @@ class ActionsPermissionsEventSubscriber implements EventSubscriberInterface {
   * @var \Drupal\Component\EventDispatcher\Event $event
   *   The event to respond to.
   */
  public function alterActions(Event $event) {
  public function alterActions(Event $event): void {

    // Don't alter definitions if this is invoked by the
    // own permissions creating method.
+3 −1
Original line number Diff line number Diff line
views_bulk_operations.action_config.views_bulk_operations_example:
# Since 4.x preliminary configuration schema should be defined for actions
# that have additional configuration.
views_bulk_operations.action_config.views_bulk_operations_example_simple:
  type: views_bulk_operations_action_config
  label: 'Example preliminary configuration'
  mapping:
+9 −11
Original line number Diff line number Diff line
@@ -48,18 +48,18 @@ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase impl
    // ...
    $this->messenger()->addMessage($entity->label() . ' - ' . $entity->language()->getId() . ' - ' . $entity->id());
    return $this->t('Example action (configuration: @configuration)', [
      '@configuration' => Markup::create(print_r($this->configuration, TRUE))
      '@configuration' => Markup::create(\print_r($this->configuration, TRUE)),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function buildPreConfigurationForm(array $form, array $values, FormStateInterface $form_state) {
  public function buildPreConfigurationForm(array $form, array $values, FormStateInterface $form_state): array {
    $form['example_preconfig_setting'] = [
      '#title' => $this->t('Example setting'),
      '#type' => 'textfield',
      '#default_value' => isset($values['example_preconfig_setting']) ? $values['example_preconfig_setting'] : '',
      '#default_value' => $values['example_preconfig_setting'] ?? '',
    ];
    return $form;
  }
@@ -72,15 +72,14 @@ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase impl
   *
   * @param array $form
   *   Form array.
   * @param Drupal\Core\Form\FormStateInterface $form_state
   *   The form state object.
   * @param \Drupal\views_bulk_operations_example\Plugin\Action\Drupal\Core\Form\FormStateInterface $form_state The form state object.
   *
   * @return array
   *   The configuration form.
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
    $form['example_config_setting'] = [
      '#title' => t('Example setting pre-execute'),
      '#title' => \t('Example setting pre-execute'),
      '#type' => 'textfield',
      '#default_value' => $form_state->getValue('example_config_setting'),
    ];
@@ -95,10 +94,9 @@ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase impl
   *
   * @param array $form
   *   Form array.
   * @param Drupal\Core\Form\FormStateInterface $form_state
   *   The form state object.
   * @param \Drupal\views_bulk_operations_example\Plugin\Action\Drupal\Core\Form\FormStateInterface $form_state The form state object.
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
    // This is not required here, when this method is not defined,
    // form values are assigned to the action configuration by default.
    // This function is a must only when user input processing is needed.
@@ -108,7 +106,7 @@ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase impl
  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
  public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
    // If certain fields are updated, access should be checked against them as well.
    // @see Drupal\Core\Field\FieldUpdateActionBase::access().
    return $object->access('update', $account, $return_as_object);
+4 −5
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@

namespace Drupal\views_bulk_operations\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\views\Views;
use Drupal\views_bulk_operations\Form\ViewsBulkOperationsFormTrait;

@@ -20,9 +20,8 @@ class ViewsBulkOperationsAccess implements AccessInterface {
  /**
   * The tempstore service.
   *
   * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
   */
  protected $tempStoreFactory;
  protected PrivateTempStoreFactory $tempStoreFactory;

  /**
   * Object constructor.
Loading