You are here

class AjaxLinksApiSettingsForm in Ajaxify Drupal with JQuery Ajax 8

Displays the Ajax links API settings form.

Hierarchy

Expanded class hierarchy of AjaxLinksApiSettingsForm

1 file declares its use of AjaxLinksApiSettingsForm
ajax_links_api.module in ./ajax_links_api.module
Make any links or create new links via jQuery Ajax.
1 string reference to 'AjaxLinksApiSettingsForm'
ajax_links_api.routing.yml in ./ajax_links_api.routing.yml
ajax_links_api.routing.yml

File

src/Form/AjaxLinksApiSettingsForm.php, line 11

Namespace

Drupal\ajax_links_api\Form
View source
class AjaxLinksApiSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'ajax_links_api_settings';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = \Drupal::config('ajax_links_api.admin_settings');
    $form['ajax_links_api_trigger'] = array(
      '#type' => 'textarea',
      '#title' => t('jQuery selector to trigger ajax (One per line)'),
      '#default_value' => $config
        ->get('ajax_links_api.trigger'),
      '#description' => t('Just like jQuery, for example by providing ".content a" will ajaxify all link under .content. You can also exclude some selectors by specifying ! (for example "!#toolbar a")'),
    );
    $form['ajax_links_api_selector'] = array(
      '#type' => 'textfield',
      '#title' => t('Default Target DIV'),
      '#default_value' => $config
        ->get('ajax_links_api.selector'),
      '#description' => t('This can be override for indivdual link by providing rel. Check Demo.'),
    );
    $form['ajax_links_api_html5'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable URL and Title change (for HTML5 Only)'),
      '#default_value' => $config
        ->get('ajax_links_api.html5'),
      '#description' => t('Change URL and Title according to ajax content. This will work only for HTML5 supported browsers. Tested on latest Chrome,Firefox.'),
    );
    $form['ajax_links_api_scripts_included'] = array(
      '#type' => 'checkbox',
      '#title' => t('Included js-bottom-placeholder in template'),
      '#default_value' => $config
        ->get('ajax_links_api.scripts_included'),
      '#description' => t('If you removed js-bottom-placeholder from html--ajax.html.twig, uncheck this. For details, please check https://drupal.org/node/1923320'),
    );
    $form['ajax_links_api_vpager'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remove ?ajax=1 from Views pager'),
      '#default_value' => $config
        ->get('ajax_links_api.vpager'),
      '#description' => t('Remove ?ajax=1 from Views pager. For details, please check http://drupal.org/node/1907376.'),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    \Drupal::configFactory()
      ->getEditable('ajax_links_api.admin_settings')
      ->set('ajax_links_api.trigger', $values['ajax_links_api_trigger'])
      ->set('ajax_links_api.selector', $values['ajax_links_api_selector'])
      ->set('ajax_links_api.html5', $values['ajax_links_api_html5'])
      ->set('ajax_links_api.scripts_included', $values['ajax_links_api_scripts_included'])
      ->set('ajax_links_api.vpager', $values['ajax_links_api_vpager'])
      ->save();
    return parent::submitForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function getEditableConfigNames() {
    return [
      'ajax_links_api.settings',
    ];
  }

  /**
   * Get trigger classes/ids.
   *
   * Ajax links triggers now come in two varieties:
   *
   *   positive triggers: these are selectors that are used to select
   *     a set of links
   *   negative triggers: these are selectors used in .not() to remove
   *     links from the set of matched ones
   *
   * The user can specify these in the admin/config screen. Negative triggers
   * are those listed with a "!" as the first character.
   */
  public static function ajaxLinksApiGetTriggers() {
    $config = \Drupal::config('ajax_links_api.admin_settings');
    $trigger = $config
      ->get('ajax_links_api.trigger');
    $trigger = explode("\n", $trigger);

    // Trim all entries.
    $trigger = array_map('trim', $trigger);

    // Filter out empty lines.
    $trigger = array_filter($trigger);
    $positive_triggers = array();
    $negative_triggers = array();
    foreach ($trigger as $this_trigger) {
      if (preg_match('/^!/', $this_trigger)) {
        $negative_triggers[] = substr($this_trigger, 1);
      }
      else {
        $positive_triggers[] = $this_trigger;
      }
    }
    $positive_trigger = implode(',', $positive_triggers);
    $negative_trigger = implode(',', $negative_triggers);
    return array(
      $positive_trigger,
      $negative_trigger,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxLinksApiSettingsForm::ajaxLinksApiGetTriggers public static function Get trigger classes/ids.
AjaxLinksApiSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
AjaxLinksApiSettingsForm::getEditableConfigNames public function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
AjaxLinksApiSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
AjaxLinksApiSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.