class ActionAjaxTest

Same name in other branches
  1. 9 core/modules/action/tests/action_form_ajax_test/src/Plugin/Action/ActionAjaxTest.php \Drupal\action_form_ajax_test\Plugin\Action\ActionAjaxTest
  2. 8.9.x core/modules/action/tests/action_form_ajax_test/src/Plugin/Action/ActionAjaxTest.php \Drupal\action_form_ajax_test\Plugin\Action\ActionAjaxTest
  3. 11.x core/modules/action/tests/action_form_ajax_test/src/Plugin/Action/ActionAjaxTest.php \Drupal\action_form_ajax_test\Plugin\Action\ActionAjaxTest

Plugin used for testing AJAX in action config entity forms.

Hierarchy

Expanded class hierarchy of ActionAjaxTest

File

core/modules/action/tests/action_form_ajax_test/src/Plugin/Action/ActionAjaxTest.php, line 15

Namespace

Drupal\action_form_ajax_test\Plugin\Action
View source
class ActionAjaxTest extends ConfigurableActionBase {
    
    /**
     * {@inheritdoc}
     */
    public function defaultConfiguration() {
        return [
            'party_time' => '',
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
        $result = AccessResult::allowed();
        return $return_as_object ? $result : $result->isAllowed();
    }
    
    /**
     * {@inheritdoc}
     */
    public function execute() {
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
        $having_a_party = $form_state->getValue('having_a_party', !empty($this->configuration['party_time']));
        $form['having_a_party'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Are we having a party?'),
            '#ajax' => [
                'wrapper' => 'party-container',
                'callback' => [
                    $this,
                    'partyCallback',
                ],
            ],
            '#default_value' => $having_a_party,
        ];
        $form['container'] = [
            '#type' => 'container',
            '#prefix' => '<div id="party-container">',
            '#suffix' => '</div>',
        ];
        if ($having_a_party) {
            $form['container']['party_time'] = [
                '#type' => 'textfield',
                '#title' => $this->t('Party time'),
                '#default_value' => $this->configuration['party_time'],
            ];
        }
        return $form;
    }
    
    /**
     * Callback for party checkbox.
     */
    public function partyCallback(array $form, FormStateInterface $form_state) {
        return $form['container'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
        $this->configuration['party_time'] = $form_state->getValue('party_time');
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ActionAjaxTest::access public function Checks object access. Overrides ActionInterface::access
ActionAjaxTest::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
ActionAjaxTest::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableActionBase::defaultConfiguration
ActionAjaxTest::execute public function Executes the plugin. Overrides ExecutableInterface::execute
ActionAjaxTest::partyCallback public function Callback for party checkbox.
ActionAjaxTest::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
ActionBase::executeMultiple public function Executes the plugin for an array of objects. Overrides ActionInterface::executeMultiple 3
ConfigurableActionBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies 1
ConfigurableActionBase::getConfiguration public function Gets this plugin&#039;s configuration. Overrides ConfigurableInterface::getConfiguration
ConfigurableActionBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ConfigurableActionBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 2
ConfigurableActionBase::__construct public function 7
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 6
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 2

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.