trait AjaxFormTrait

Same name in other branches
  1. 8.x-3.x src/Form/AjaxFormTrait.php \Drupal\ctools\Form\AjaxFormTrait

Provides helper methods for using an AJAX modal.

Hierarchy

1 file declares its use of AjaxFormTrait
BlockDisplayVariant.php in src/Plugin/DisplayVariant/BlockDisplayVariant.php

File

src/Form/AjaxFormTrait.php, line 11

Namespace

Drupal\ctools\Form
View source
trait AjaxFormTrait {
    
    /**
     * Gets attributes for use with an AJAX modal.
     *
     * @return array
     *   The array of attributes.
     */
    public static function getAjaxAttributes() {
        return [
            'class' => [
                'use-ajax',
            ],
            'data-dialog-type' => 'modal',
            'data-dialog-options' => Json::encode([
                'width' => 'auto',
            ]),
        ];
    }
    
    /**
     * Gets attributes for use with an add button AJAX modal.
     *
     * @return array
     *   The array of attributes.
     */
    public static function getAjaxButtonAttributes() {
        return NestedArray::mergeDeep(AjaxFormTrait::getAjaxAttributes(), [
            'class' => [
                'button',
                'button--small',
                'button-action',
            ],
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary
AjaxFormTrait::getAjaxAttributes public static function Gets attributes for use with an AJAX modal.
AjaxFormTrait::getAjaxButtonAttributes public static function Gets attributes for use with an add button AJAX modal.