Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('The label for this page.'), '#default_value' => $this->entity->label(), '#required' => TRUE, '#maxlength' => '255'];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $this->entity->id(), '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'exists']]];
     $form['path'] = ['#type' => 'textfield', '#title' => $this->t('Path'), '#maxlength' => 255, '#default_value' => $this->entity->getPath(), '#required' => TRUE, '#element_validate' => [[$this, 'validatePath']]];
     return parent::form($form, $form_state);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $vocabulary = $this->entity;
     if ($vocabulary->isNew()) {
         $form['#title'] = $this->t('Add vocabulary');
     } else {
         $form['#title'] = $this->t('Edit vocabulary');
     }
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $vocabulary->label(), '#maxlength' => 255, '#required' => TRUE);
     $form['vid'] = array('#type' => 'machine_name', '#default_value' => $vocabulary->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('exists' => array($this, 'exists'), 'source' => array('name')));
     $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $vocabulary->getDescription());
     // $form['langcode'] is not wrapped in an
     // if ($this->moduleHandler->moduleExists('language')) check because the
     // language_select form element works also without the language module being
     // installed. https://www.drupal.org/node/1749954 documents the new element.
     $form['langcode'] = array('#type' => 'language_select', '#title' => $this->t('Vocabulary language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $vocabulary->language()->getId());
     if ($this->moduleHandler->moduleExists('language')) {
         $form['default_terms_language'] = array('#type' => 'details', '#title' => $this->t('Terms language'), '#open' => TRUE);
         $form['default_terms_language']['default_language'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'taxonomy_term', 'bundle' => $vocabulary->id()), '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()));
     }
     // Set the hierarchy to "multiple parents" by default. This simplifies the
     // vocabulary form and standardizes the term form.
     $form['hierarchy'] = array('#type' => 'value', '#value' => '0');
     return parent::form($form, $form_state, $vocabulary);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $menu_block = $this->entity;
     // Label field.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Administrative Label'), '#maxlength' => 255, '#default_value' => $menu_block->label(), '#required' => TRUE);
     // ID field.
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $menu_block->id(), '#machine_name' => array('exists' => '\\Drupal\\menu_block\\Entity\\MenuBlock::load'), '#disabled' => !$menu_block->isNew());
     // Menu selection.
     $options = [];
     $menu_storage = \Drupal::entityManager()->getStorage('menu');
     foreach ($menu_storage->loadMultiple() as $menu) {
         $options[$menu->id()] = $menu->label();
     }
     $form['menu'] = ['#type' => 'select', '#title' => $this->t('Menu'), '#options' => $options, '#default_value' => $menu_block->getMenu()];
     // Block title.
     $form['block_title'] = array('#type' => 'textfield', '#title' => $this->t('Block Title'), '#maxlength' => 255, '#default_value' => $menu_block->getBlockTitle());
     // Administrative block title.
     $form['admin_block_title'] = array('#type' => 'textfield', '#title' => $this->t('Administrative Block Title'), '#maxlength' => 255, '#default_value' => $menu_block->getAdminBlockTitle(), '#required' => TRUE);
     // Starting level.
     // TODO - Look at AJAX based on menu selected
     $form['starting_level'] = array('#type' => 'select', '#title' => $this->t('Starting Menu Level'), '#maxlength' => 255, '#default_value' => $menu_block->getStartingLevel(), '#options' => array('0' => 'Root', '1' => 'Level 1', '2' => 'Level 2', '3' => 'Level 3', '4' => 'Level 4', '5' => 'Level 5', '6' => 'Level 6', '7' => 'Level 7', '8' => 'Level 8'), '#required' => TRUE, '#description' => $this->t("Select which level of the menu the menu block begins."));
     // Maximum depth.
     $form['maximum_depth'] = array('#type' => 'select', '#title' => $this->t('Starting Menu Level'), '#maxlength' => 255, '#default_value' => $menu_block->getMaximumDepth(), '#options' => array('0' => 'All levels', '1' => '1 level', '2' => '2 levels', '3' => '3 levels', '4' => '4 levels', '5' => '5 levels', '6' => '6 levels', '7' => '7 levels', '8' => '8 levels'), '#required' => TRUE, '#description' => $this->t("Select how many levels of the menu block should render."));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $keys = $this->key_repository->getKeys();
     if (empty($keys)) {
         drupal_set_message('No system keys (admin/config/system/key) are installed to manage encryption profiles.');
     }
     /** @var $encryption_profile \Drupal\encrypt\Entity\EncryptionProfile */
     $encryption_profile = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $encryption_profile->label(), '#description' => $this->t("Label for the encryption profile."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $encryption_profile->id(), '#machine_name' => array('exists' => '\\Drupal\\encrypt\\Entity\\EncryptionProfile::load'), '#disabled' => !$encryption_profile->isNew());
     /** @var $key \Drupal\key\Entity\KeyInterface */
     foreach ($keys as $key) {
         $key_id = $key->id();
         $key_title = $key->label();
         $keys[$key_id] = (string) $key_title;
     }
     if ($profile_key = $encryption_profile->getEncryptionKey()) {
         $default_key = $profile_key;
     }
     $form['encryption_key'] = array('#type' => 'select', '#title' => $this->t('Encryption Key'), '#description' => $this->t('Select the key used for encryption.'), '#options' => $keys, '#default_value' => empty($default_key) ? NULL : $default_key, '#required' => TRUE);
     $enc_methods = [];
     foreach ($this->encrypt_service->loadEncryptionMethods() as $plugin_id => $definition) {
         $enc_methods[$plugin_id] = (string) $definition['title'];
     }
     $form['encryption_method'] = array('#type' => 'select', '#title' => $this->t('Encryption Method'), '#description' => $this->t('Select the method used for encryption'), '#options' => $enc_methods, '#default_value' => $encryption_profile->getEncryptionMethod());
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /* @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $bundle */
     $bundle = $form_state->getFormObject()->getEntity();
     $form['enable_moderation_state'] = ['#type' => 'checkbox', '#title' => $this->t('Enable moderation states.'), '#description' => $this->t('Content of this type must transition through moderation states in order to be published.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'enabled', FALSE)];
     // Add a special message when moderation is being disabled.
     if ($bundle->getThirdPartySetting('content_moderation', 'enabled', FALSE)) {
         $form['enable_moderation_state_note'] = ['#type' => 'item', '#description' => $this->t('After disabling moderation, any existing forward drafts will be accessible via the "Revisions" tab.'), '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => FALSE]]]];
     }
     $states = $this->entityTypeManager->getStorage('moderation_state')->loadMultiple();
     $label = function (ModerationState $state) {
         return $state->label();
     };
     $options_published = array_map($label, array_filter($states, function (ModerationState $state) {
         return $state->isPublishedState();
     }));
     $options_unpublished = array_map($label, array_filter($states, function (ModerationState $state) {
         return !$state->isPublishedState();
     }));
     $form['allowed_moderation_states_unpublished'] = ['#type' => 'checkboxes', '#title' => $this->t('Allowed moderation states (Unpublished)'), '#description' => $this->t('The allowed unpublished moderation states this content-type can be assigned.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($options_unpublished)), '#options' => $options_unpublished, '#required' => TRUE, '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     $form['allowed_moderation_states_published'] = ['#type' => 'checkboxes', '#title' => $this->t('Allowed moderation states (Published)'), '#description' => $this->t('The allowed published moderation states this content-type can be assigned.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($options_published)), '#options' => $options_published, '#required' => TRUE, '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     // The key of the array needs to be a user-facing string so we have to fully
     // render the translatable string to a real string, or else PHP errors on an
     // object used as an array key.
     $options = [$this->t('Unpublished')->render() => $options_unpublished, $this->t('Published')->render() => $options_published];
     $form['default_moderation_state'] = ['#type' => 'select', '#title' => $this->t('Default moderation state'), '#options' => $options, '#description' => $this->t('Select the moderation state for new content'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'), '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     $form['#entity_builders'][] = [$this, 'formBuilderCallback'];
     return parent::form($form, $form_state);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /* @var \Drupal\crm_core_contact\Entity\ContactType $type */
     $type = $this->entity;
     $form['name'] = array('#title' => $this->t('Name'), '#type' => 'textfield', '#default_value' => $type->name, '#description' => $this->t('The human-readable name of this contact type. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), '#required' => TRUE, '#size' => 32);
     $form['type'] = array('#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('exists' => 'Drupal\\crm_core_contact\\Entity\\ContactType::load', 'source' => array('name')), '#description' => $this->t('A unique machine-readable name for this contact type. It must only contain lowercase letters, numbers, and underscores.'));
     $form['description'] = array('#title' => $this->t('Description'), '#type' => 'textarea', '#default_value' => $type->description, '#description' => $this->t('Describe this contact type.'));
     // Primary fields section.
     $form['primary_fields_container'] = array('#type' => 'fieldset', '#title' => $this->t('Primary Fields'), '#description' => $this->t('Primary fields are used to tell other modules what fields to use for common communications tasks such as sending an email, addressing an envelope, etc. Use the fields below to indicate the primary fields for this contact type.'));
     // @todo Move primary fields array to some hook. This Would allow extend this
     // list to other modules. This hook should return arra('key'=>t('Name')).
     $default_primary_fields = array('email', 'address', 'phone');
     //    $primary_fields = variable_get('crm_core_contact_default_primary_fields', $default_primary_fields);
     $primary_fields = $default_primary_fields;
     $options = array();
     if (isset($type->type)) {
         /* @var \Drupal\Core\Field\FieldDefinitionInterface[] $instances */
         $instances = \Drupal::entityManager()->getFieldDefinitions('crm_core_contact', $type->type);
         $instances = isset($instances[$type->type]) ? $instances[$type->type] : array();
         foreach ($instances as $instance) {
             $options[$instance->getName()] = $instance->getLabel();
         }
     }
     foreach ($primary_fields as $primary_field) {
         $form['primary_fields_container'][$primary_field] = array('#type' => 'select', '#title' => $this->t('Primary @field field', array('@field' => $primary_field)), '#default_value' => empty($type->primary_fields[$primary_field]) ? '' : $type->primary_fields[$primary_field], '#empty_value' => '', '#empty_option' => $this->t('--Please Select--'), '#options' => $options);
     }
     return $form;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $tax_type */
     $tax_type = $this->entity;
     /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $zone_storage */
     $zone_storage = $this->entityTypeManager->getStorage('zone');
     $zones = $zone_storage->loadMultipleOverrideFree();
     // @todo Filter by zone scope == 'tax'.
     $zones = array_map(function ($zone) {
         return $zone->label();
     }, $zones);
     $form['name'] = ['#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $tax_type->getName(), '#maxlength' => 255, '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $tax_type->getId(), '#machine_name' => ['exists' => '\\Drupal\\commerce_tax\\Entity\\TaxType::load', 'source' => ['name']], '#required' => TRUE, '#disabled' => !$tax_type->isNew()];
     $form['zone'] = ['#type' => 'select', '#title' => $this->t('Zone'), '#default_value' => $tax_type->getZoneId(), '#options' => $zones, '#required' => TRUE];
     if ($tax_type->isNew()) {
         $link = Link::createFromRoute('Zones page', 'entity.zone.collection')->toString();
         $form['zone']['#description'] = $this->t('To add a new zone visit the @link.', ['@link' => $link]);
     }
     $form['compound'] = ['#type' => 'checkbox', '#title' => $this->t('Compound'), '#description' => $this->t("Compound tax is calculated on top of a primary tax. For example, Canada's Provincial Sales Tax (PST) is compound, calculated on a price that already includes the Goods and Services Tax (GST)."), '#default_value' => $tax_type->isCompound()];
     $form['displayInclusive'] = ['#type' => 'checkbox', '#title' => $this->t('Display inclusive'), '#default_value' => $tax_type->isDisplayInclusive()];
     $form['roundingMode'] = ['#type' => 'radios', '#title' => $this->t('Rounding mode'), '#default_value' => $tax_type->getRoundingMode() ?: TaxType::ROUND_HALF_UP, '#options' => [TaxType::ROUND_HALF_UP => $this->t('Round up'), TaxType::ROUND_HALF_DOWN => $this->t('Round down'), TaxType::ROUND_HALF_EVEN => $this->t('Round even'), TaxType::ROUND_HALF_ODD => $this->t('Round odd')], '#required' => TRUE];
     $form['tag'] = ['#type' => 'textfield', '#title' => $this->t('Tag'), '#description' => $this->t('Used by the resolvers to analyze only the tax types relevant to them. For example, the EuTaxTypeResolver would analyze only the tax types with the "EU" tag.'), '#default_value' => $tax_type->getTag()];
     return $form;
 }
 /**
  * Overrides Drupal\Core\Entity\EntityForm::form().
  *
  * @param array $form
  *   A nested array form elements comprising the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping
  *   The entity being edited.
  *
  * @return array
  *   The array containing the complete form.
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     if ($this->operation == 'duplicate') {
         $form['#title'] = $this->t('<em>Duplicate responsive image mapping</em> @label', array('@label' => $this->entity->label()));
         $this->entity = $this->entity->createDuplicate();
     }
     if ($this->operation == 'edit') {
         $form['#title'] = $this->t('<em>Edit responsive image mapping</em> @label', array('@label' => $this->entity->label()));
     }
     /** @var \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping */
     $responsive_image_mapping = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $responsive_image_mapping->label(), '#description' => $this->t("Example: 'Hero image' or 'Author image'."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $responsive_image_mapping->id(), '#machine_name' => array('exists' => '\\Drupal\\responsive_image\\Entity\\ResponsiveImageMapping::load', 'source' => array('label')), '#disabled' => (bool) $responsive_image_mapping->id() && $this->operation != 'duplicate');
     if ((bool) $responsive_image_mapping->id() && $this->operation != 'duplicate') {
         $description = $this->t('Select a breakpoint group from the enabled themes.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your selected mappings.");
     } else {
         $description = $this->t('Select a breakpoint group from the enabled themes.');
     }
     $form['breakpointGroup'] = array('#type' => 'select', '#title' => $this->t('Breakpoint group'), '#default_value' => $responsive_image_mapping->getBreakpointGroup() != '' ? $responsive_image_mapping->getBreakpointGroup()->id() : '', '#options' => breakpoint_group_select_options(), '#required' => TRUE, '#description' => $description);
     $image_styles = image_style_options(TRUE);
     $image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this->t('- empty image -');
     foreach ($responsive_image_mapping->getMappings() as $breakpoint_id => $mapping) {
         foreach ($mapping as $multiplier => $image_style) {
             $breakpoint = $responsive_image_mapping->getBreakpointGroup()->getBreakpointById($breakpoint_id);
             $label = $multiplier . ' ' . $breakpoint->name . ' [' . $breakpoint->mediaQuery . ']';
             $form['mappings'][$breakpoint_id][$multiplier] = array('#type' => 'select', '#title' => String::checkPlain($label), '#options' => $image_styles, '#default_value' => $image_style, '#description' => $this->t('Select an image style for this breakpoint.'));
         }
     }
     $form['#tree'] = TRUE;
     return parent::form($form, $form_state, $responsive_image_mapping);
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $type = $this->entity;
     if ($this->operation == 'add') {
         $form['#title'] = String::checkPlain($this->t('Add content type'));
     } elseif ($this->operation == 'edit') {
         $form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label()));
     }
     $node_settings = $type->getModuleSettings('node');
     // Prepare node options to be used for 'checkboxes' form element.
     $keys = array_keys(array_filter($node_settings['options']));
     $node_settings['options'] = array_combine($keys, $keys);
     $form['name'] = array('#title' => t('Name'), '#type' => 'textfield', '#default_value' => $type->name, '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add content</em> page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), '#required' => TRUE, '#size' => 30);
     $form['type'] = array('#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => $type->isLocked(), '#machine_name' => array('exists' => 'node_type_load', 'source' => array('name')), '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array('%node-add' => t('Add content'))));
     $form['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => $type->description, '#description' => t('Describe this content type. The text will be displayed on the <em>Add content</em> page.'));
     $form['additional_settings'] = array('#type' => 'vertical_tabs', '#attached' => array('library' => array('node/drupal.content_types')));
     $form['submission'] = array('#type' => 'details', '#title' => t('Submission form settings'), '#group' => 'additional_settings', '#open' => TRUE);
     $form['submission']['title_label'] = array('#title' => t('Title field label'), '#type' => 'textfield', '#default_value' => $type->title_label, '#required' => TRUE);
     $form['submission']['preview'] = array('#type' => 'radios', '#title' => t('Preview before submitting'), '#parents' => array('settings', 'node', 'preview'), '#default_value' => $node_settings['preview'], '#options' => array(DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), DRUPAL_REQUIRED => t('Required')));
     $form['submission']['help'] = array('#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => $type->help, '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'));
     $form['workflow'] = array('#type' => 'details', '#title' => t('Publishing options'), '#group' => 'additional_settings');
     $form['workflow']['options'] = array('#type' => 'checkboxes', '#title' => t('Default options'), '#parents' => array('settings', 'node', 'options'), '#default_value' => $node_settings['options'], '#options' => array('status' => t('Published'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')), '#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'));
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = language_get_default_configuration('node', $type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'node', 'bundle' => $type->id()), '#default_value' => $language_configuration);
     }
     $form['display'] = array('#type' => 'details', '#title' => t('Display settings'), '#group' => 'additional_settings');
     $form['display']['submitted'] = array('#type' => 'checkbox', '#title' => t('Display author and date information.'), '#parents' => array('settings', 'node', 'submitted'), '#default_value' => $node_settings['submitted'], '#description' => t('Author username and publish date will be displayed.'));
     return $form;
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $domain = $this->entity;
     $domains = \Drupal::service('domain.loader')->loadMultiple();
     // Create defaults if this is the first domain.
     if (empty($domains)) {
         $domain->addProperty('hostname', \Drupal::service('domain.creator')->createHostname());
         $domain->addProperty('name', \Drupal::config('system.site')->get('name'));
     }
     $form['domain_id'] = array('#type' => 'value', '#value' => $domain->getDomainId());
     $form['hostname'] = array('#type' => 'textfield', '#title' => $this->t('Hostname'), '#size' => 40, '#maxlength' => 80, '#default_value' => $domain->getHostname(), '#description' => $this->t('The canonical hostname, using the full <em>subdomain.example.com</em> format. Leave off the http:// and the trailing slash and do not include any paths.<br />If this domain uses a custom http(s) port, you should specify it here, e.g.: <em>subdomain.example.com:1234</em><br />The hostname may contain only lowercase alphanumeric characters, dots, dashes, and a colon (if using alternative ports).'));
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $domain->id(), '#machine_name' => array('source' => array('hostname'), 'exists' => '\\Drupal\\domain\\Entity\\Domain::load'));
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#size' => 40, '#maxlength' => 80, '#default_value' => $domain->label(), '#description' => $this->t('The human-readable name is shown in domain lists and may be used as the title tag.'));
     // Do not use the :// suffix when storing data.
     $add_suffix = FALSE;
     $form['scheme'] = array('#type' => 'radios', '#title' => $this->t('Domain URL scheme'), '#options' => array('http' => 'http://', 'https' => 'https://'), '#default_value' => $domain->getScheme($add_suffix), '#description' => $this->t('This URL scheme will be used when writing links and redirects to this domain and its resources.'));
     $form['status'] = array('#type' => 'radios', '#title' => $this->t('Domain status'), '#options' => array(1 => $this->t('Active'), 0 => $this->t('Inactive')), '#default_value' => (int) $domain->status(), '#description' => $this->t('"Inactive" domains are only accessible to user roles with that assigned permission.'));
     $form['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#delta' => count(\Drupal::service('domain.loader')->loadMultiple()) + 1, '#default_value' => $domain->getWeight(), '#description' => $this->t('The sort order for this record. Lower values display first.'));
     $form['is_default'] = array('#type' => 'checkbox', '#title' => $this->t('Default domain'), '#default_value' => $domain->isDefault(), '#description' => $this->t('If a URL request fails to match a domain record, the settings for this domain will be used. Only one domain can be default.'));
     $required = \Drupal::service('domain.validator')->getRequiredFields();
     foreach ($form as $key => $element) {
         if (in_array($key, $required)) {
             $form[$key]['#required'] = TRUE;
         }
     }
     return $form;
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\embed\EmbedButtonInterface $button */
     $button = $this->entity;
     $form_state->setTemporaryValue('embed_button', $button);
     $form['label'] = ['#title' => $this->t('Label'), '#type' => 'textfield', '#default_value' => $button->label(), '#description' => t('The human-readable name of this embed button. This text will be displayed when the user hovers over the CKEditor button. This name must be unique.'), '#required' => TRUE, '#size' => 30];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $button->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$button->isNew(), '#machine_name' => ['exists' => ['Drupal\\embed\\Entity\\EmbedButton', 'load']], '#description' => $this->t('A unique machine-readable name for this embed button. It must only contain lowercase letters, numbers, and underscores.')];
     $form['type_id'] = ['#type' => 'select', '#title' => $this->t('Embed type'), '#options' => $this->embedTypeManager->getDefinitionOptions(), '#default_value' => $button->getTypeId(), '#required' => TRUE, '#ajax' => ['callback' => '::updateTypeSettings', 'effect' => 'fade'], '#disabled' => !$button->isNew()];
     if (count($form['type_id']['#options']) == 0) {
         drupal_set_message($this->t('No embed types found.'), 'warning');
     }
     // Add the embed type plugin settings.
     $form['type_settings'] = ['#type' => 'container', '#tree' => TRUE, '#prefix' => '<div id="embed-type-settings-wrapper">', '#suffix' => '</div>'];
     try {
         if ($plugin = $button->getTypePlugin()) {
             $form['type_settings'] = $plugin->buildConfigurationForm($form['type_settings'], $form_state);
         }
     } catch (PluginNotFoundException $exception) {
         drupal_set_message($exception->getMessage(), 'error');
         watchdog_exception('embed', $exception);
         $form['type_id']['#disabled'] = FALSE;
     }
     $config = $this->config('embed.settings');
     $upload_location = $config->get('file_scheme') . '://' . $config->get('upload_directory') . '/';
     $form['icon_file'] = ['#title' => $this->t('Button icon'), '#type' => 'managed_file', '#description' => $this->t('Icon for the button to be shown in CKEditor toolbar. Leave empty to use the default Entity icon.'), '#upload_location' => $upload_location, '#upload_validators' => ['file_validate_extensions' => ['gif png jpg jpeg'], 'file_validate_image_resolution' => ['32x32', '16x16']]];
     if ($file = $button->getIconFile()) {
         $form['icon_file']['#default_value'] = ['target_id' => $file->id()];
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var ScheduledUpdateType $scheduled_update_type */
     $scheduled_update_type = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $scheduled_update_type->label(), '#description' => $this->t("Label for the Scheduled update type."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $scheduled_update_type->id(), '#machine_name' => array('exists' => '\\Drupal\\scheduled_updates\\Entity\\ScheduledUpdateType::load'), '#disabled' => !$scheduled_update_type->isNew());
     $default_type = $scheduled_update_type->getUpdateEntityType();
     $form['update_entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity Type'), '#description' => $this->t('The entity type to update. This <strong>cannot</strong> be changed after this type is created.'), '#options' => $this->entityTypeOptions(), '#default_value' => $default_type, '#required' => TRUE, '#disabled' => !$scheduled_update_type->isNew()];
     // @todo Remove when bug is fixed.
     if (!$form['update_entity_type']['#disabled']) {
         // Just to duplicate issues on d.o for now.
         $form['update_entity_type']['#description'] .= '<br /><strong>**KNOWN BUG**</strong> : Ajax error when selecting one entity type and then selecting another: https://www.drupal.org/node/2643934';
     }
     // On Add give the user the option to create referencing entity reference field.
     $ajax = ['#limit_validation_errors' => array(), '#ajax' => array('wrapper' => 'type-dependent-set', 'callback' => '::updateTypeDependentSet', 'method' => 'replace')];
     $form['update_entity_type'] += $ajax;
     $form['type_dependent_elements'] = [];
     // @todo Should the runner configuration form even be displayed before entity type is selected?
     $form['type_dependent_elements']['update_runner'] = $this->createRunnerElements($form_state);
     $form['type_dependent_elements']['update_runner']['id'] += $ajax;
     if ($this->entity->isNew()) {
         $form['type_dependent_elements']['reference_settings'] = $this->createNewFieldsElements($form, $form_state);
     }
     $form['type_dependent_elements'] += ['#type' => 'container', '#prefix' => '<div id="type-dependent-set" >', '#suffix' => '</div>'];
     $form['field_map'] = $this->createFieldMapElements();
     /* You will need additional form elements for your custom properties. */
     return $form;
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
     $form['#entity'] = $bundle = $this->entity;
     $form_state->set('bundle', $bundle->id());
     if ($this->operation == 'add') {
         $form['#title'] = $this->t('Add media bundle');
     } elseif ($this->operation == 'edit') {
         $form['#title'] = $this->t('Edit %label media bundle', array('%label' => $bundle->label()));
     }
     $form['label'] = array('#title' => t('Label'), '#type' => 'textfield', '#default_value' => $bundle->label(), '#description' => t('The human-readable name of this media bundle.'), '#required' => TRUE, '#size' => 30);
     // @todo: '#disabled' not always FALSE.
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $bundle->id(), '#maxlength' => 32, '#disabled' => FALSE, '#machine_name' => array('exists' => array('\\Drupal\\media_entity\\Entity\\MediaBundle', 'exists'), 'source' => array('label')), '#description' => t('A unique machine-readable name for this media bundle.'));
     $form['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => $bundle->getDescription(), '#description' => t('Describe this media bundle. The text will be displayed on the <em>Add new media</em> page.'));
     $plugins = $this->mediaTypeManager->getDefinitions();
     $options = array();
     foreach ($plugins as $plugin => $definition) {
         $options[$plugin] = $definition['label'];
     }
     $form['type'] = array('#type' => 'select', '#title' => t('Type provider'), '#default_value' => $bundle->getType()->getPluginId(), '#options' => $options, '#description' => t('Media type provider plugin that is responsible for additional logic related to this media.'));
     $form['type_configuration'] = array('#type' => 'fieldset', '#title' => t('Type provider configuration'), '#tree' => TRUE);
     foreach ($plugins as $plugin => $definition) {
         $plugin_configuration = $bundle->getType()->getPluginId() == $plugin ? $bundle->type_configuration : array();
         $form['type_configuration'][$plugin] = array('#type' => 'container', '#states' => array('visible' => array(':input[name="type"]' => array('value' => $plugin))));
         /** @var \Drupal\media_entity\MediaTypeBase $instance */
         $instance = $this->mediaTypeManager->createInstance($plugin, $plugin_configuration);
         $form['type_configuration'][$plugin] += $instance->buildConfigurationForm([], $form_state);
         // Store the instance for validate and submit handlers.
         $this->configurableInstances[$plugin] = $instance;
     }
     return $form;
 }
Esempio n. 14
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $backup_migrate_schedule = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Schedule Name'), '#maxlength' => 255, '#default_value' => $backup_migrate_schedule->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $backup_migrate_schedule->id(), '#machine_name' => array('exists' => '\\Drupal\\backup_migrate\\Entity\\Schedule::load'), '#disabled' => !$backup_migrate_schedule->isNew());
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Schedule enabled'), '#default_value' => $backup_migrate_schedule->get('enabled'));
     $bam = backup_migrate_get_service_object([], ['nobrowser' => TRUE]);
     $form['source_id'] = DrupalConfigHelper::getSourceSelector($bam, t('Backup Source'));
     $form['destination_id'] = DrupalConfigHelper::getDestinationSelector($bam, t('Backup Destination'));
     $form['settings_profile_id'] = DrupalConfigHelper::getSettingsProfileSelector(t('Settings Profile'));
     $period = Schedule::secondsToPeriod($backup_migrate_schedule->get('period'));
     $form['period_container'] = array('#parents' => array(), '#type' => 'fieldset', '#title' => $this->t('Frequency'), '#field_prefix' => $this->t('Run every'), '#attributes' => array('class' => array('container-inline', 'fieldgroup', 'form-composite')));
     $form['period_container']['period_number'] = array('#type' => 'number', '#default_value' => $period['number'], '#min' => 1, '#title' => $this->t('Period number'), '#title_display' => 'invisible', '#size' => 2);
     $form['period_container']['period_type'] = ['#type' => 'select', '#title' => $this->t('Period type'), '#title_display' => 'invisible', '#options' => [], '#default_value' => $period['type']];
     foreach (Schedule::getPeriodTypes() as $key => $type) {
         $form['period_container']['period_type']['#options'][$key] = $type['title'];
     }
     //    $form['keep'] = array(
     //      '#type' => 'textfield',
     //      '#title' => $this->t('Number to keep'),
     //      '#default_value' => $backup_migrate_schedule->get('keep'),
     //      '#description' => $this->t('The number of backups to retain. Once this number is reached, the oldest backup will be deleted to make room for the most recent backup. Leave blank to keep all backups.'),
     //      '#size' => 10,
     //    );
     return $form;
 }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $entity = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => 'Label', '#default_value' => $entity->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $entity->id(), '#required' => TRUE, '#machine_name' => array('exists' => [$this, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+'));
     $form['weight'] = array('#type' => 'weight', '#title' => 'Weight', '#default_value' => $entity->get('weight'));
     $form['style'] = array('#type' => 'select', '#title' => 'Image style', '#options' => array(), '#default_value' => $entity->get('style'), '#access' => FALSE);
     if ($this->moduleHandler->moduleExists('image')) {
         $form['style']['#access'] = TRUE;
         $form['style']['#options'] = image_style_options();
     }
     // The main premise of entity forms is that we get to work with an entity
     // object at all times instead of checking submitted values from the form
     // state.
     $size = $entity->get('size');
     $form['size_wrapper'] = array('#type' => 'container', '#attributes' => array('id' => 'size-wrapper'));
     $form['size_wrapper']['size'] = array('#type' => 'select', '#title' => 'Size', '#options' => array('custom' => 'Custom'), '#empty_option' => '- None -', '#default_value' => $size, '#ajax' => array('callback' => '::updateSize', 'wrapper' => 'size-wrapper'));
     $form['size_wrapper']['size_submit'] = array('#type' => 'submit', '#value' => t('Change size'), '#attributes' => array('class' => array('js-hide')), '#submit' => array(array(get_class($this), 'changeSize')));
     $form['size_wrapper']['size_value'] = array('#type' => 'select', '#title' => 'Custom size value', '#options' => array('small' => 'Small', 'medium' => 'Medium', 'large' => 'Large'), '#default_value' => $entity->get('size_value'), '#access' => !empty($size));
     $form['langcode'] = array('#type' => 'language_select', '#title' => t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $entity->language()->getId());
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Save');
     $form['actions']['delete'] = array('#type' => 'submit', '#value' => 'Delete');
     return $form;
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $field_storage = $this->entity->getFieldStorageDefinition();
     $bundles = $this->entityManager->getBundleInfo($this->entity->getTargetEntityTypeId());
     $form_title = $this->t('%field settings for %bundle', array('%field' => $this->entity->getLabel(), '%bundle' => $bundles[$this->entity->bundle]['label']));
     $form['#title'] = $form_title;
     if ($field_storage->isLocked()) {
         $form['locked'] = array('#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->entity->getLabel())));
         return $form;
     }
     // Build the configurable field values.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => $this->entity->getLabel() ?: $field_storage->getName(), '#required' => TRUE, '#weight' => -20);
     $form['description'] = array('#type' => 'textarea', '#title' => $this->t('Help text'), '#default_value' => $this->entity->getDescription(), '#rows' => 5, '#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => $this->displayAllowedTags())) . '<br />' . $this->t('This field supports tokens.'), '#weight' => -10);
     $form['required'] = array('#type' => 'checkbox', '#title' => $this->t('Required field'), '#default_value' => $this->entity->isRequired(), '#weight' => -5);
     // Create an arbitrary entity object (used by the 'default value' widget).
     $ids = (object) array('entity_type' => $this->entity->getTargetEntityTypeId(), 'bundle' => $this->entity->bundle, 'entity_id' => NULL);
     $form['#entity'] = _field_create_entity_from_ids($ids);
     $items = $form['#entity']->get($this->entity->getName());
     $item = $items->first() ?: $items->appendItem();
     // Add field settings for the field type and a container for third party
     // settings that modules can add to via hook_form_FORM_ID_alter().
     $form['settings'] = array('#tree' => TRUE, '#weight' => 10);
     $form['settings'] += $item->fieldSettingsForm($form, $form_state);
     $form['third_party_settings'] = array('#tree' => TRUE, '#weight' => 11);
     // Add handling for default value.
     if ($element = $items->defaultValuesForm($form, $form_state)) {
         $element = array_merge($element, array('#type' => 'details', '#title' => $this->t('Default value'), '#open' => TRUE, '#tree' => TRUE, '#description' => $this->t('The default value for this field, used when creating new content.')));
         $form['default_value'] = $element;
     }
     return $form;
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $matcher = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $matcher->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('ID'), '#maxlength' => 255, '#default_value' => $matcher->id(), '#description' => $this->t('ID of the matcher.'), '#required' => TRUE, '#machine_name' => array('exists' => 'Drupal\\crm_core_match\\Entity\\Matcher::load'), '#disabled' => !$matcher->isNew());
     $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $matcher->getDescription(), '#maxlength' => 255, '#description' => $this->t('Description of the matcher.'));
     // Get all plugins.
     if ($matcher->isNew()) {
         $plugin_types = array();
         foreach (crm_core_match_matcher_manager()->getDefinitions() as $plugin_id => $definition) {
             $plugin_types[$plugin_id] = $definition['label'];
         }
         // If there is only one plugin (matching engine) available, set it as
         // default option and hide the select menu.
         $default_value = NULL;
         $single_plugin = count($plugin_types) == 1;
         if ($single_plugin) {
             $default_value = key($plugin_types);
             $matcher->set('plugin_id', $default_value);
         }
         $form['plugin_id'] = array('#type' => 'select', '#default_value' => $default_value, '#options' => $plugin_types, '#empty_value' => $this->t('- Select -'), '#title' => $this->t('Matcher Plugin'), '#limit_validation_errors' => array(array('plugin_id')), '#submit' => array('::submitSelectPlugin'), '#required' => TRUE, '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::ajaxReplacePluginSpecificForm', 'wrapper' => 'crm-core-match-match-engine-plugin', 'method' => 'replace'), '#access' => !$single_plugin);
         $form['select_plugin'] = array('#type' => 'submit', '#value' => $this->t('Select plugin'), '#limit_validation_errors' => array(array('plugin_id')), '#submit' => array('::submitSelectPlugin'), '#attributes' => array('class' => array('js-hide')), '#access' => !$single_plugin);
     } else {
         $form['current_plugin_id'] = array('#type' => 'item', '#title' => $this->t('Match engine'), '#markup' => $matcher->getPlugin()->getPluginDefinition()['label']);
     }
     $form['plugin_container'] = array('#type' => 'container', '#prefix' => '<div id="crm-core-match-match-engine-plugin">', '#suffix' => '</div>');
     if ($plugin = $matcher->getPlugin()) {
         $form['plugin_container']['configuration'] = array('#type' => 'details', '#open' => TRUE, '#title' => $this->t('@plugin configuration', ['@plugin' => $matcher->getPluginTitle()]), '#tree' => TRUE);
         $form['plugin_container']['configuration'] += (array) $plugin->buildConfigurationForm($form['plugin_container']['configuration'], $form_state);
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $metatag_defaults = $this->entity;
     $metatag_manager = \Drupal::service('metatag.manager');
     $form['#ajax_wrapper_id'] = 'metatag-defaults-form-ajax-wrapper';
     $ajax = ['wrapper' => $form['#ajax_wrapper_id'], 'callback' => '::rebuildForm'];
     $form['#prefix'] = '<div id="' . $form['#ajax_wrapper_id'] . '">';
     $form['#suffix'] = '</div>';
     $default_type = NULL;
     if (!empty($metatag_defaults)) {
         $default_type = $metatag_defaults->getOriginalId();
     } else {
         $form_state->set('default_type', $default_type);
     }
     $token_types = empty($default_type) ? [] : [explode('__', $default_type)[0]];
     // Add the token browser at the top.
     $form += \Drupal::service('metatag.token')->tokenBrowser($token_types);
     // If this is a new Metatag defaults, then list available bundles.
     if ($metatag_defaults->isNew()) {
         $options = $this->getAvailableBundles();
         $form['id'] = ['#type' => 'select', '#title' => t('Type'), '#description' => t('Select the type of default meta tags you would like to add.'), '#options' => $options, '#required' => TRUE, '#default_value' => $default_type, '#ajax' => $ajax + ['trigger_as' => ['name' => 'select_id_submit']]];
         $form['select_id_submit'] = ['#type' => 'submit', '#value' => $this->t('Submit'), '#name' => 'select_id_submit', '#ajax' => $ajax, '#attributes' => ['class' => ['js-hide']]];
         $values = [];
     } else {
         $values = $metatag_defaults->get('tags');
     }
     // Add metatag form fields.
     $form = $metatag_manager->form($values, $form);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $field_label = $form_state->get('field_config')->label();
     $form['#title'] = $field_label;
     $form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $field_label)) . '</p>';
     // See if data already exists for this field.
     // If so, prevent changes to the field settings.
     if ($this->entity->hasData()) {
         $form['#prefix'] = '<div class="messages messages--error">' . $this->t('There is data for this field in the database. The field settings can no longer be changed.') . '</div>' . $form['#prefix'];
     }
     // Add settings provided by the field module. The field module is
     // responsible for not returning settings that cannot be changed if
     // the field already has data.
     $form['settings'] = array('#weight' => -10, '#tree' => TRUE);
     // Create an arbitrary entity object, so that we can have an instantiated
     // FieldItem.
     $ids = (object) array('entity_type' => $form_state->get('entity_type_id'), 'bundle' => $form_state->get('bundle'), 'entity_id' => NULL);
     $entity = _field_create_entity_from_ids($ids);
     $items = $entity->get($this->entity->getName());
     $item = $items->first() ?: $items->appendItem();
     $form['settings'] += $item->storageSettingsForm($form, $form_state, $this->entity->hasData());
     // Build the configurable field values.
     $cardinality = $this->entity->getCardinality();
     $form['cardinality_container'] = array('#parents' => array(), '#type' => 'fieldset', '#title' => $this->t('Allowed number of values'), '#attributes' => array('class' => array('container-inline', 'fieldgroup', 'form-composite')));
     $form['cardinality_container']['cardinality'] = array('#type' => 'select', '#title' => $this->t('Allowed number of values'), '#title_display' => 'invisible', '#options' => array('number' => $this->t('Limited'), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited')), '#default_value' => $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 'number');
     $form['cardinality_container']['cardinality_number'] = array('#type' => 'number', '#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : 1, '#min' => 1, '#title' => $this->t('Limit'), '#title_display' => 'invisible', '#size' => 2, '#states' => array('visible' => array(':input[name="cardinality"]' => array('value' => 'number')), 'disabled' => array(':input[name="cardinality"]' => array('value' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))));
     return $form;
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $comment_type = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, '#default_value' => $comment_type->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $comment_type->id(), '#machine_name' => array('exists' => '\\Drupal\\comment\\Entity\\CommentType::load'), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$comment_type->isNew());
     $form['description'] = array('#type' => 'textarea', '#default_value' => $comment_type->getDescription(), '#description' => t('Describe this comment type. The text will be displayed on the <em>Comment types</em> administration overview page.'), '#title' => t('Description'));
     if ($comment_type->isNew()) {
         $options = array();
         foreach ($this->entityManager->getDefinitions() as $entity_type) {
             // Only expose entities that have field UI enabled, only those can
             // get comment fields added in the UI.
             if ($entity_type->get('field_ui_base_route')) {
                 $options[$entity_type->id()] = $entity_type->getLabel();
             }
         }
         $form['target_entity_type_id'] = array('#type' => 'select', '#default_value' => $comment_type->getTargetEntityTypeId(), '#title' => t('Target entity type'), '#options' => $options, '#description' => t('The target entity type can not be changed after the comment type has been created.'));
     } else {
         $form['target_entity_type_id_display'] = array('#type' => 'item', '#markup' => $this->entityManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), '#title' => t('Target entity type'));
     }
     if ($this->moduleHandler->moduleExists('content_translation')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', $comment_type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'comment', 'bundle' => $comment_type->id()), '#default_value' => $language_configuration);
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     return $form;
 }
Esempio n. 21
0
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Profile Name'),
      '#default_value' => $this->entity->label(),
      '#description' => $this->t('The human-readable name of this  profile. This name must be unique.'),
      '#required' => TRUE,
      '#size' => 30,
    ];

    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $this->entity->id(),
      '#machine_name' => [
        'exists' => ['\Drupal\linkit\Entity\Profile', 'load']
      ],
      '#disabled' => !$this->entity->isNew(),
    ];

    $form['description'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Description'),
      '#default_value' => $this->entity->getDescription(),
      '#description' => $this->t('The text will be displayed on the <em>profile collection</em> page.'),
    ];

    $form['additional_settings'] = array(
      '#type' => 'vertical_tabs',
      '#weight' => 99,
    );

    return parent::form($form, $form_state);
  }
Esempio n. 22
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, array &$form_state)
 {
     $entity = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Role name'), '#default_value' => $entity->label(), '#size' => 30, '#required' => TRUE, '#maxlength' => 64, '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'));
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $entity->id(), '#required' => TRUE, '#disabled' => !$entity->isNew(), '#size' => 30, '#maxlength' => 64, '#machine_name' => array('exists' => 'user_role_load'));
     $form['weight'] = array('#type' => 'value', '#value' => $entity->getWeight());
     return parent::form($form, $form_state, $entity);
 }
Esempio n. 23
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::form().
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $alias = $this->entity;
     $form['domain_id'] = array('#type' => 'value', '#value' => $alias->getDomainId());
     $form['pattern'] = array('#type' => 'textfield', '#title' => $this->t('Pattern'), '#size' => 40, '#maxlength' => 80, '#default_value' => $alias->getPattern(), '#description' => $this->t('The matching pattern for this alias.'), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $alias->id(), '#machine_name' => array('source' => array('pattern'), 'exists' => '\\Drupal\\domain_alias\\Entity\\DomainAlias::load'));
     $form['redirect'] = array('#type' => 'select', '#options' => $this->redirectOptions(), '#default_value' => $alias->getRedirect(), '#description' => $this->t('Redirect status'));
     return parent::form($form, $form_state, $alias);
 }
Esempio n. 24
0
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $currency = $this->entity;

    $form['name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Name'),
      '#default_value' => $currency->getName(),
      '#maxlength' => 255,
      '#required' => TRUE,
    ];
    $form['currencyCode'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Currency code'),
      '#default_value' => $currency->getCurrencyCode(),
      '#element_validate' => ['::validateCurrencyCode'],
      '#pattern' => '[A-Z]{3}',
      '#placeholder' => 'XXX',
      '#maxlength' => 3,
      '#size' => 3,
      '#disabled' => !$currency->isNew(),
      '#required' => TRUE,
    ];
    $form['numericCode'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Numeric code'),
      '#default_value' => $currency->getNumericCode(),
      '#element_validate' => ['::validateNumericCode'],
      '#pattern' => '[\d]{3}',
      '#placeholder' => '999',
      '#maxlength' => 3,
      '#size' => 3,
      '#required' => TRUE,
    ];
    $form['symbol'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Symbol'),
      '#default_value' => $currency->getSymbol(),
      '#maxlength' => 255,
      '#required' => TRUE,
    ];
    $form['fractionDigits'] = [
      '#type' => 'number',
      '#title' => $this->t('Fraction digits'),
      '#description' => $this->t('The number of digits after the decimal sign.'),
      '#default_value' => $currency->getFractionDigits() ?: 2,
      '#min' => 0,
      '#required' => TRUE,
    ];
    $form['status'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enabled'),
      '#default_value' => $currency->status(),
    ];

    return $form;
  }
Esempio n. 25
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $entity = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => t('Set name'), '#description' => t('The new set is created by copying items from your default shortcut set.'), '#required' => TRUE, '#default_value' => $entity->label());
     $form['id'] = array('#type' => 'machine_name', '#machine_name' => array('exists' => '\\Drupal\\shortcut\\Entity\\ShortcutSet::load', 'source' => array('label'), 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-'), '#default_value' => $entity->id(), '#disabled' => !$entity->isNew(), '#maxlength' => 23);
     $form['actions']['submit']['#value'] = t('Create new set');
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $default_entity = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $default_entity->label(), '#description' => $this->t("Label for the Default entity."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $default_entity->id(), '#machine_name' => array('exists' => '\\Drupal\\unicef42\\Entity\\DefaultEntity::load'), '#disabled' => !$default_entity->isNew());
     /* You will need additional form elements for your custom properties. */
     return $form;
 }
Esempio n. 27
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $element = parent::form($form, $form_state);
     $element['label'] = array('#type' => 'textfield', '#title' => t('Name'), '#default_value' => $this->entity->label(), '#maxlength' => 255, '#required' => TRUE);
     $element['id'] = array('#type' => 'machine_name', '#title' => t('Machine-readable name'), '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => array('exists' => array($this, 'exists')));
     $element['pattern'] = array('#type' => 'textfield', '#title' => t('Format'), '#default_value' => $this->entity->get('pattern'), '#maxlength' => 255, '#required' => TRUE);
     $element['help'] = $this->nameFormatHelp();
     return $element;
 }
Esempio n. 28
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $paragraphs_type = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $paragraphs_type->label(), '#description' => $this->t("Label for the Paragraphs type."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $paragraphs_type->id(), '#machine_name' => array('exists' => 'paragraphs_type_load'), '#disabled' => !$paragraphs_type->isNew());
     // You will need additional form elements for your custom properties.
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['label'] = array('#type' => 'textfield', '#title' => 'Name', '#maxlength' => 100, '#description' => t('Name of the date format'), '#default_value' => $this->entity->label());
     $form['id'] = array('#type' => 'machine_name', '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".')));
     $form['date_format_pattern'] = array('#type' => 'textfield', '#title' => t('Format string'), '#maxlength' => 100, '#description' => $this->t('A user-defined date format. See the <a href="http://php.net/manual/function.date.php">PHP manual</a> for available options.'), '#required' => TRUE, '#attributes' => ['data-drupal-date-formatter' => 'source'], '#field_suffix' => ' <small class="js-hide" data-drupal-date-formatter="preview">' . $this->t('Displayed as %date_format', ['%date_format' => '']) . '</small>');
     $form['langcode'] = array('#type' => 'language_select', '#title' => t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $this->entity->language()->getId());
     $form['#attached']['drupalSettings']['dateFormats'] = $this->dateFormatter->getSampleDateFormats();
     $form['#attached']['library'][] = 'system/drupal.system.date';
     return parent::form($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['settings'] = ['#type' => 'details', '#title' => $this->t('Settings'), '#open' => $this->entity->isNew()];
     $form['settings']['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => $this->entity->label(), '#required' => TRUE];
     $form['settings']['id'] = ['#type' => 'machine_name', '#description' => $this->t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => ['exists' => [$this, 'exists'], 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'source' => ['settings', 'label'], 'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".')]];
     // @todo enter a real tag field here.
     $form['settings']['tags'] = ['#type' => 'textfield', '#title' => $this->t('Tags'), '#default_value' => implode(', ', $this->entity->getTags()), '#description' => $this->t('Enter a list of comma-separated tags here; e.g., "notification, publishing".'), '#required' => FALSE];
     $form['settings']['description'] = ['#type' => 'textarea', '#default_value' => $this->entity->getDescription(), '#description' => $this->t('Enter a description for this component.'), '#title' => $this->t('Description')];
     return parent::form($form, $form_state);
 }