You are here

ModalPageFieldHelper.php in Modal 8.3

Same filename and directory in other branches
  1. 8.2 src/Helper/ModalPageFieldHelper.php

File

src/Helper/ModalPageFieldHelper.php
View source
<?php

namespace Drupal\modal_page\Helper;

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Modal Page Field Helper.
 */
class ModalPageFieldHelper {
  use StringTranslationTrait;

  /**
   * Get Field Role.
   */
  public function getFieldRole() {
    $label = $this
      ->t('Who can access this Modal');
    $description = $this
      ->t('If no role is selected this Modal will be visible to everyone.');
    $fieldRoles = BaseFieldDefinition::create('list_string');
    $fieldRoles
      ->setLabel($label);
    $fieldRoles
      ->setSettings([
      'allowed_values' => user_role_names(),
    ]);
    $fieldRoles
      ->setDescription($description);
    $fieldRoles
      ->setRequired(FALSE);
    $fieldRoles
      ->setCardinality(-1);
    $fieldRoles
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 6,
    ]);
    $fieldRoles
      ->setDisplayConfigurable('form', TRUE);
    return $fieldRoles;
  }

  /**
   * Get "Don't show again label".
   */
  public function getFieldDontShowAgainLabel() {
    $dontShowAgainLabel = BaseFieldDefinition::create('string');
    $dontShowAgainLabel
      ->setLabel($this
      ->t("Label"));
    $dontShowAgainLabel
      ->setDefaultValue($this
      ->t("Don't show again"));
    $dontShowAgainLabel
      ->setDescription($this
      ->t("If blank the value will be <b>Don't show again</b>"));
    $dontShowAgainLabel
      ->setDisplayConfigurable('form', TRUE);
    $dontShowAgainLabel
      ->setDisplayConfigurable('view', TRUE);
    $dontShowAgainLabel
      ->setSettings([
      'max_length' => 255,
      'text_processing' => 0,
    ]);
    $dontShowAgainLabel
      ->setDisplayOptions('form', [
      'type' => 'string_textfield',
      'weight' => -5,
    ]);
    $dontShowAgainLabel
      ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'string',
      'weight' => -5,
    ]);
    return $dontShowAgainLabel;
  }

  /**
   * Get Field "Close Modal ESC Key".
   */
  public function getFieldCloseModalEscKey() {
    $closeModalEscKey = BaseFieldDefinition::create('boolean');
    $closeModalEscKey
      ->setLabel($this
      ->t("Close Modal pressing ESC key"));
    $closeModalEscKey
      ->setDefaultValue(TRUE);
    $closeModalEscKey
      ->setDescription($this
      ->t("If unchecked, the end-user will not be able to close the modal clicking the ESC key"));
    $closeModalEscKey
      ->setDisplayConfigurable('form', TRUE);
    $closeModalEscKey
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'settings' => [
        'display_label' => TRUE,
      ],
      'weight' => -5,
    ]);
    return $closeModalEscKey;
  }

  /**
   * Get Field "Close Modal Clicking Outside".
   */
  public function getFieldCloseClickingOutside() {
    $closeModalClickingOutside = BaseFieldDefinition::create('boolean');
    $closeModalClickingOutside
      ->setLabel($this
      ->t("Close Modal clicking outside the modal"));
    $closeModalClickingOutside
      ->setDefaultValue(TRUE);
    $closeModalClickingOutside
      ->setDescription($this
      ->t("If unchecked, the end-user will not be able to close the modal clicking outside the modal"));
    $closeModalClickingOutside
      ->setDisplayConfigurable('form', TRUE);
    $closeModalClickingOutside
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'settings' => [
        'display_label' => TRUE,
      ],
      'weight' => -5,
    ]);
    return $closeModalClickingOutside;
  }

}

Classes

Namesort descending Description
ModalPageFieldHelper Modal Page Field Helper.