Verified Commit 9ddbc2c7 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3449259 by narendraR, alexpott, catch, Wim Leers: Add validation...

Issue #3449259 by narendraR, alexpott, catch, Wim Leers: Add validation constraints to system.action.*
parent a0466c55
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -286,6 +286,8 @@ system.menu.*:
system.action.*:
  type: config_entity
  label: 'System action'
  constraints:
    FullyValidatable: ~
  mapping:
    id:
      type: machine_name
@@ -302,6 +304,12 @@ system.action.*:
    type:
      type: string
      label: 'Type'
      # Action can be specified without type.
      # @see \Drupal\action_test\Plugin\Action\NoType
      nullable: true
      constraints:
        NotBlank:
          allowNull: true
    plugin:
      type: string
      label: 'Plugin'
+4 −1
Original line number Diff line number Diff line
@@ -19,7 +19,10 @@ public function isConfigurable();
  /**
   * Returns the operation type.
   *
   * @return string
   * The operation type can be NULL if no type is specified.
   *
   * @return string|null
   *   The operation type, or NULL if no type is specified.
   */
  public function getType();

+2 −2
Original line number Diff line number Diff line
@@ -57,9 +57,9 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En
  /**
   * The action type.
   *
   * @var string
   * @var string|null
   */
  protected $type;
  protected $type = NULL;

  /**
   * The configuration of the action.
+6 −0
Original line number Diff line number Diff line
# Schema for the configuration files of the Action test module.

action.configuration.action_test_no_type:
  type: mapping
  label: 'Configuration for action_test_no_type plugin'
  mapping: {}
+22 −0
Original line number Diff line number Diff line
@@ -101,4 +101,26 @@ public function testDependencies(): void {
    $this->assertSame($expected, $action->calculateDependencies()->getDependencies());
  }

  /**
   * Tests no type specified action.
   */
  public function testNoTypeAction(): void {
    // Create an action config entity using the action_test_no_type plugin.
    $action = Action::create([
      'id' => 'action_test_no_type_action',
      'label' => 'Test Action with No Type',
      'plugin' => 'action_test_no_type',
    ]);
    $action->save();

    // Reload the action to ensure it's saved correctly.
    $action = Action::load('action_test_no_type_action');

    // Assert that the action was saved and loaded correctly.
    $this->assertNotNull($action, 'The action config entity was saved and loaded correctly.');
    $this->assertSame('action_test_no_type_action', $action->id(), 'The action ID is correct.');
    $this->assertSame('Test Action with No Type', $action->label(), 'The action label is correct.');
    $this->assertNull($action->getType(), 'The action type is correctly set to NULL.');
  }

}
Loading