View source
<?php
namespace Drupal\modal_page\Helper;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class ModalPageFieldHelper {
use StringTranslationTrait;
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;
}
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;
}
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;
}
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;
}
}