Exemplo n.º 1
1
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // If the form is rebuilding.
     if ($form_state->isRebuilding()) {
         // If an encryption method change triggered the rebuild.
         if ($form_state->getTriggeringElement()['#name'] == 'encryption_method') {
             // Update the encryption method plugin.
             $this->updateEncryptionMethod($form_state);
         }
     } elseif ($this->operation == "edit") {
         // Only when the form is first built.
         /* @var $encryption_profile \Drupal\encrypt\Entity\EncryptionProfile */
         $encryption_profile = $this->entity;
         $this->originalProfile = clone $encryption_profile;
     }
     return parent::buildForm($form, $form_state);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $rate = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('This name will appear to the customer when this tax is applied to an order.'), '#default_value' => $rate->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $rate->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => '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['rate'] = array('#type' => 'textfield', '#title' => $this->t('Rate'), '#description' => $this->t('The tax rate as a percent or decimal. Examples: 6%, .06'), '#size' => 15, '#default_value' => (double) $rate->getRate() * 100.0 . '%', '#required' => TRUE);
     $form['jurisdiction'] = array('#type' => 'textfield', '#title' => $this->t('Jurisdiction'), '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), '#default_value' => $rate->getJurisdiction(), '#required' => FALSE);
     $form['shippable'] = array('#type' => 'radios', '#title' => $this->t('Taxed products'), '#options' => array(0 => $this->t('Apply tax to any product regardless of its shippability.'), 1 => $this->t('Apply tax to shippable products only.')), '#default_value' => (int) $rate->isForShippable());
     // TODO: Remove the need for a special case for product kit module.
     $options = array();
     foreach (node_type_get_names() as $type => $name) {
         if ($type != 'product_kit' && uc_product_is_product($type)) {
             $options[$type] = $name;
         }
     }
     $options['blank-line'] = $this->t('"Blank line" product');
     $form['product_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed product types'), '#description' => $this->t('Apply taxes to the specified product types/classes.'), '#default_value' => $rate->getProductTypes(), '#options' => $options);
     $options = array();
     foreach (_uc_line_item_list() as $id => $line_item) {
         if (!in_array($id, ['subtotal', 'tax_subtotal', 'total', 'tax_display'])) {
             $options[$id] = $line_item['title'];
         }
     }
     $form['line_item_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Taxed line items'), '#description' => $this->t('Adds the checked line item types to the total before applying this tax.'), '#default_value' => $rate->getLineItemTypes(), '#options' => $options);
     $form['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#description' => $this->t('Taxes are sorted by weight and then applied to the order sequentially. This value is important when taxes need to include other tax line items.'), '#default_value' => $rate->getWeight());
     $form['display_include'] = array('#type' => 'checkbox', '#title' => $this->t('Include this tax when displaying product prices.'), '#default_value' => $rate->isIncludedInPrice());
     $form['inclusion_text'] = array('#type' => 'textfield', '#title' => $this->t('Tax inclusion text'), '#description' => $this->t('This text will be displayed near the price to indicate that it includes tax.'), '#default_value' => $rate->getInclusionText());
     return $form;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     /** @var \Drupal\rng\EventTypeInterface $event_type */
     $event_type = $this->entity;
     if (!$event_type->isNew()) {
         $form['#title'] = $this->t('Edit event type %label configuration', array('%label' => $event_type->label()));
     }
     if ($event_type->isNew()) {
         $bundle_options = [];
         // Generate a list of fieldable bundles which are not events.
         foreach ($this->entityManager->getDefinitions() as $entity_type) {
             if ($entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
                 foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) {
                     if (!$this->eventManager->eventType($entity_type->id(), $bundle)) {
                         $bundle_options[(string) $entity_type->getLabel()][$entity_type->id() . '.' . $bundle] = $bundle_info['label'];
                     }
                 }
             }
         }
         if ($this->moduleHandler->moduleExists('node')) {
             $form['#attached']['library'][] = 'rng/rng.admin';
             $form['entity_type'] = ['#type' => 'radios', '#options' => NULL, '#title' => $this->t('Event entity type'), '#required' => TRUE];
             $form['entity_type']['node']['radio'] = ['#type' => 'radio', '#title' => $this->t('Create a new content type'), '#description' => $this->t('Create a content type to use as an event type.'), '#return_value' => "node", '#parents' => array('entity_type'), '#default_value' => 'node'];
             $form['entity_type']['existing']['radio'] = ['#type' => 'radio', '#title' => $this->t('Use existing bundle'), '#description' => $this->t('Use an existing entity/bundle combination.'), '#return_value' => "existing", '#parents' => array('entity_type'), '#default_value' => ''];
             $form['entity_type']['existing']['container'] = ['#type' => 'container', '#attributes' => ['class' => ['rng-radio-indent']]];
         }
         $form['entity_type']['existing']['container']['bundle'] = array('#type' => 'select', '#title' => $this->t('Bundle'), '#options' => $bundle_options, '#default_value' => $event_type->id(), '#disabled' => !$event_type->isNew(), '#empty_option' => $bundle_options ? NULL : t('No Bundles Available'));
     }
     $form['settings'] = array('#type' => 'fieldset', '#title' => $this->t('Settings'));
     // Mirror permission.
     $form['access']['mirror_update'] = array('#group' => 'settings', '#type' => 'checkbox', '#title' => t('Mirror manage registrations with update permission'), '#description' => t('Allow users to <strong>manage registrations</strong> if they have <strong>update</strong> permission on an event entity.'), '#default_value' => (bool) ($event_type->getEventManageOperation() !== NULL ? $event_type->getEventManageOperation() : TRUE));
     return $form;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $display_id = NULL)
 {
     if (isset($display_id) && $form_state->has('display_id') && $display_id !== $form_state->get('display_id')) {
         throw new \InvalidArgumentException('Mismatch between $form_state->get(\'display_id\') and $display_id.');
     }
     $this->displayID = $form_state->has('display_id') ? $form_state->get('display_id') : $display_id;
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  *
  * @param string $field_config
  *   The ID of the field config whose field storage config is being edited.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $field_config = NULL)
 {
     if ($field_config) {
         $field = FieldConfig::load($field_config);
         $form_state->set('field_config', $field);
         $form_state->set('entity_type_id', $field->getTargetEntityTypeId());
         $form_state->set('bundle', $field->getTargetBundle());
     }
     return parent::buildForm($form, $form_state);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get the from from the base class.
     $form = parent::buildForm($form, $form_state);
     $eck_entity_type = $this->entity;
     // Build the form.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $eck_entity_type->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $eck_entity_type->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => '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".'), '#disabled' => !$eck_entity_type->isNew());
     return $form;
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $country = $this->entity;
     $form['#title'] = $this->t('Edit %country', array('%country' => $country->label()));
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $country->getName());
     $form['address_format'] = array('#type' => 'textarea', '#title' => $this->t('Address format'), '#default_value' => implode("\r\n", $country->getAddressFormat()), '#rows' => 7);
     $form['help'] = array('#type' => 'details', '#title' => $this->t('Address format variables'), '#collapsed' => TRUE);
     $form['help']['text'] = array('#theme' => 'table', '#header' => array($this->t('Variable'), $this->t('Description')), '#rows' => array(array('!first_name', $this->t("Customer's first name")), array('!last_name', $this->t("Customer's last name")), array('!company', $this->t('Company name')), array('!street1', $this->t('First street address field')), array('!street2', $this->t('Second street address field')), array('!city', $this->t('City name')), array('!zone_name', $this->t('Full name of the zone')), array('!zone_code', $this->t('Abbreviation of the zone')), array('!postal_code', $this->t('Postal code')), array('!country_name', $this->t('Name of the country')), array('!country_code2', $this->t('2 digit country abbreviation')), array('!country_code3', $this->t('3 digit country abbreviation'))), '#prefix' => '<p>' . $this->t('The following variables should be used in configuring addresses for the countries you ship to:') . '</p>', '#suffix' => '<p>' . $this->t('Adding _if to any country variable will make it display only for addresses whose country is different than the default store country.') . '</p>');
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $registration_type = $this->entity;
     if (!$registration_type->isNew()) {
         $form['#title'] = $this->t('Edit registration type %label', array('%label' => $registration_type->label()));
     }
     // Build the form.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $registration_type->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $registration_type->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$registration_type->isNew());
     $form['description'] = array('#type' => 'textarea', '#title' => t('Description'), '#default_value' => $registration_type->description, '#description' => t('Description will be displayed when a user is choosing which registration type to use for an event.'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $form['#title'] = $this->getQuestion();
     $form['#attributes']['class'][] = 'confirmation';
     $form['description'] = array('#markup' => $this->getDescription());
     $form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
     // By default, render the form using theme_confirm_form().
     if (!isset($form['#theme'])) {
         $form['#theme'] = 'confirm_form';
     }
     return $form;
 }
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::form().
  *
  * Builds the entity add/edit form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   An associative array containing the current state of the form.
  *
  * @return array
  *   An associative array containing the migration group add/edit form.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need from the base class.
     $form = parent::buildForm($form, $form_state);
     /** @var MigrationGroupInterface $migration_group */
     $migration_group = $this->entity;
     // Build the form.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $migration_group->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $migration_group->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => '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".'), '#disabled' => !$migration_group->isNew());
     $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#maxlength' => 255, '#default_value' => $migration_group->get('description'));
     $form['source_type'] = array('#type' => 'textfield', '#title' => $this->t('Source type'), '#description' => $this->t('Type of source system the group is migrating from, for example "Drupal 6" or "WordPress 4".'), '#maxlength' => 255, '#default_value' => $migration_group->get('source_type'));
     // Return the form.
     return $form;
 }
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::form().
  *
  * Builds the entity add/edit form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param array $form_state
  *   An associative array containing the current state of the form.
  *
  * @return array
  *   An associative array containing the robot add/edit form.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need from the base class.
     $form = parent::buildForm($form, $form_state);
     // Drupal provides the entity to us as a class variable. If this is an
     // existing entity, it will be populated with existing values as class
     // variables. If this is a new entity, it will be a new object with the
     // class of our entity. Drupal knows which class to call from the
     // annotation on our Robot class.
     $robot = $this->entity;
     // Build the form.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $robot->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $robot->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => '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".'), '#disabled' => !$robot->isNew());
     $form['floopy'] = array('#type' => 'checkbox', '#title' => $this->t('Floopy'), '#default_value' => $robot->floopy);
     // Return the form.
     return $form;
 }
Exemplo n.º 12
0
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::form().
  *
  * Builds the entity add/edit form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param FormStateInterface $form_state
  *   An instance of FormStateInterface containing the current state of the form.
  *
  * @return array
  *   An associative array containing the FlagMapping add/edit form.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need from the base class.
     $form = parent::buildForm($form, $form_state);
     // Drupal provides the entity to us as a class variable. If this is an
     // existing entity, it will be populated with existing values as class
     // variables. If this is a new entity, it will be a new object with the
     // class of our entity. Drupal knows which class to call from the
     // annotation on our FlagMapping class.
     /** @var FlagMapping $mapping */
     $mapping = $this->entity;
     // Build the form.
     $form['info'] = ['#type' => 'textfield', '#title' => $this->t('Info'), '#maxlength' => 255, '#default_value' => $mapping->getInfo(), '#required' => TRUE];
     $form['source'] = ['#type' => 'select', '#title' => $this->t('Language'), '#default_value' => $mapping->getSource(), '#description' => $this->t('Select a source language.'), '#options' => $this->languageManager->getAllDefinedLanguages(), '#required' => TRUE];
     $countries = \Drupal::service('country_manager')->getList();
     $form['flag'] = ['#type' => 'select', '#title' => $this->t('Flag'), '#options' => $countries, '#empty_value' => '', '#default_value' => strtoupper($mapping->getFlag()), '#description' => $this->t('Select a target territory flag.'), '#required' => TRUE];
     // Return the form.
     return $form;
 }
Exemplo n.º 13
0
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::form().
  *
  * Builds the entity add/edit form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param array $form_state
  *   An associative array containing the current state of the form.
  *
  * @return array
  *   An associative array containing the sock add/edit form.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need from the base class.
     $form = parent::buildForm($form, $form_state);
     // Drupal provides the entity to us as a class variable. If this is an
     // existing entity, it will be populated with existing values as class
     // variables. If this is a new entity, it will be a new object with the
     // class of our entity. Drupal knows which class to call from the
     // annotation on our Sock class.
     $sock = $this->entity;
     // Build the form.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $sock->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $sock->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => '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".'), '#disabled' => !$sock->isNew());
     $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#maxlength' => 255, '#default_value' => $sock->description, '#description' => $this->t("Description of the Sock."), '#required' => TRUE);
     $form['fabric'] = array('#type' => 'textfield', '#title' => $this->t('Fabric'), '#maxlength' => 255, '#default_value' => $sock->fabric, '#description' => $this->t("Fabric of the Sock."), '#required' => TRUE);
     $form['rating'] = array('#type' => 'select', '#title' => t('Rating'), '#options' => array(0 => t('1'), 1 => t('2'), 2 => t('3'), 3 => t('4'), 4 => t('5')), '#default_value' => $sock->rating, '#description' => t('Rate your socks!'));
     // Return the form.
     return $form;
 }
Exemplo n.º 14
0
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::form().
  *
  * Builds the entity add/edit form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param array $form_state
  *   An associative array containing the current state of the form.
  *
  * @return array
  *   An associative array containing the migration add/edit form.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need from the base class.
     $form = parent::buildForm($form, $form_state);
     /** @var MigrationInterface $migration */
     $migration = $this->entity;
     // Build the form.
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $migration->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $migration->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => '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".'), '#disabled' => !$migration->isNew());
     $groups = entity_load_multiple('migration_group');
     $group_options = [];
     foreach ($groups as $group) {
         $group_options[$group->id()] = $group->label();
     }
     if (!$migration->get('migration_group') && isset($group_options['default'])) {
         $migration->set('migration_group', 'default');
     }
     $form['migration_group'] = array('#type' => 'select', '#title' => $this->t('Migration Group'), '#empty_value' => '', '#default_value' => $migration->get('migration_group'), '#options' => $group_options, '#description' => $this->t('Assign this migration to an existing group.'));
     return $form;
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need form the base class.
     $form = parent::buildForm($form, $form_state);
     // Display any API key errors.
     MollomUtilities::getAdminAPIKeyStatus();
     MollomUtilities::displayMollomTestModeWarning();
     /* @var $entity \Drupal\mollom\Entity\FormInterface */
     $entity = $this->getEntity();
     $form_id = '';
     if ($entity->isNew()) {
         // Determine if the form id selection just changed.
         $input = $form_state->getUserInput();
         if (!empty($input['id'])) {
             $form_id = $input['id'];
             $mollom_form = $entity->initialize($form_id);
         } else {
             if ($query_form_id = \Drupal::request()->query->get('form_id', '')) {
                 $form_id = $query_form_id;
                 $mollom_form = $entity->initialize($form_id);
             }
         }
     } else {
         $form_id = $entity->id();
         $mollom_form = $entity->initialize();
     }
     $enabled_fields = [];
     if ($entity->isNew() && !empty($input['id'])) {
         foreach ($mollom_form['enabled_fields'] as $value) {
             $enabled_fields[] = rawurlencode($value);
         }
         // Set defaults back.
         // See https://www.drupal.org/node/1100170
         $input['checks'] = $entity->getChecks();
         $input['enabled_fields'] = $enabled_fields;
         $form_state->setUserInput($input);
     } else {
         foreach ($entity->getEnabledFields() as $value) {
             $enabled_fields[] = rawurldecode($value);
         }
     }
     // Build the form.
     if ($entity->isNew()) {
         $options = $this->getProtectableFormOptions();
         if (empty($options)) {
             return $this->redirect('entity.mollom_form.list');
         }
         $form['#attributes']['id'] = $this->getFormId();
         $form['id'] = array('#type' => 'select', '#title' => $this->t('Mollom Form'), '#maxlength' => 255, '#options' => $options, '#default_value' => $form_id, '#empty_option' => t('Select a form to configure...'), '#required' => TRUE, '#ajax' => array('callback' => array($this, 'ajaxFormHandler'), 'wrapper' => $this->getFormId()));
         // Must select the form to protect prior to continuing.
         if (empty($form_id)) {
             return $form;
         }
     } else {
         $form['label'] = array('#title' => t('Protected form'), '#type' => 'textfield', '#default_value' => $entity->label(), '#disabled' => TRUE);
     }
     // Protection mode
     $modes = array(FormInterface::MOLLOM_MODE_ANALYSIS => $this->t('@option <em>(@recommended)</em>', array('@option' => $this->t('Text analysis'), '@recommended' => $this->t('recommended'))), FormInterface::MOLLOM_MODE_CAPTCHA => t('CAPTCHA only'));
     $form['mode'] = array('#type' => 'radios', '#title' => t('Protection mode'), '#options' => $modes, '#default_value' => isset($entity->mode) ? $entity->mode : key($modes));
     $form['mode'][FormInterface::MOLLOM_MODE_ANALYSIS] = array('#description' => t('Mollom will analyze the post and will only show a CAPTCHA when it is unsure.'));
     $form['mode'][FormInterface::MOLLOM_MODE_CAPTCHA] = array('#description' => t('A CAPTCHA will be shown for every post. Only choose this if there are too few text fields to analyze.'));
     $form['mode'][FormInterface::MOLLOM_MODE_CAPTCHA]['#description'] .= '<br />' . t('Note: Page caching is disabled on all pages containing a CAPTCHA-only protected form.');
     $all_permissions = $this->permissionHandler->getPermissions();
     // Prepend Mollom's global permission to the list.
     if (empty($mollom_form['bypass access']) || !is_array($mollom_form['bypass access'])) {
         $mollom_form['bypass access'] = [];
     }
     array_unshift($mollom_form['bypass access'], 'bypass mollom protection');
     $permissions = array();
     if (isset($mollom_form['bypass access'])) {
         foreach ($mollom_form['bypass access'] as $permission) {
             $permissions[Html::getClass($permission)] = array('title' => $all_permissions[$permission]['title'], 'url' => Url::fromRoute('user.admin_permissions'), 'fragment' => 'module-' . $all_permissions[$permission]['provider']);
         }
     }
     $form['mode']['#description'] = t('The protection is omitted for users having any of the permissions: @permission-list', array('@permission-list' => \Drupal::theme()->render('links', array('links' => $permissions))));
     // Textual analysis filters.
     $form['checks'] = array('#type' => 'checkboxes', '#title' => t('Text analysis checks'), '#options' => array('spam' => t('Spam'), 'profanity' => t('Profanity')), '#default_value' => $entity->getChecks(), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS))));
     // Profanity check requires text to analyze; unlike the spam check, there
     // is no fallback in case there is no text.
     $form['checks']['profanity']['#access'] = !empty($mollom_form['elements']);
     // Form elements defined by hook_mollom_form_info() use the
     // 'parent][child' syntax, which Form API also uses internally for
     // form_set_error(), and which allows us to recurse into nested fields
     // during processing of submitted form values. However, since we are using
     // those keys also as internal values to configure the fields to use for
     // textual analysis, we need to encode them. Otherwise, a nested field key
     // would result in the following checkbox attribute:
     //   '#name' => 'mollom[enabled_fields][parent][child]'
     // This would lead to a form validation error, because it is a valid key.
     // By encoding them, we prevent this from happening:
     //   '#name' => 'mollom[enabled_fields][parent%5D%5Bchild]'
     $elements = array();
     if (isset($mollom_form['elements']) && is_array($mollom_form['elements'])) {
         foreach ($mollom_form['elements'] as $key => $value) {
             $elements[rawurlencode($key)] = $value;
         }
     }
     $enabled_field_selections = [];
     foreach ($enabled_fields as $key => $value) {
         $enabled_field_selections[rawurlencode($key)] = rawurlencode($value);
     }
     $form['enabled_fields'] = array('#type' => 'checkboxes', '#title' => t('Text fields to analyze'), '#options' => $elements, '#default_value' => $enabled_field_selections, '#description' => t('Only enable fields that accept text (not numbers). Omit fields that contain sensitive data (e.g., credit card numbers) or computed/auto-generated values, as well as author information fields (e.g., name, e-mail).'), '#access' => !empty($mollom_form['elements']), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS))));
     $form['mapping'] = array('#type' => 'value', '#value' => $mollom_form['mapping']);
     if ($entity->isNew()) {
         $form['module'] = array('#type' => 'value', '#value' => $mollom_form['module']);
         $form['label'] = array('#type' => 'value', '#value' => $mollom_form['title']);
         $form['entity'] = array('#type' => 'value', '#value' => $mollom_form['entity']);
         $form['bundle'] = array('#type' => 'value', '#value' => $mollom_form['bundle']);
     }
     $form['strictness'] = array('#type' => 'radios', '#title' => t('Text analysis strictness'), '#options' => array('normal' => t('@option <em>(@recommended)</em>', array('@option' => t('Normal'), '@recommended' => $this->t('recommended'))), 'strict' => t('Strict: Posts are more likely classified as spam'), 'relaxed' => t('Relaxed: Posts are more likely classified as ham')), '#default_value' => $entity->getStrictness(), '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS))));
     $form['unsure'] = array('#type' => 'radios', '#title' => t('When text analysis is unsure'), '#default_value' => $entity->getUnsure(), '#options' => array('captcha' => t('@option <em>(@recommended)</em>', array('@option' => t('Show a CAPTCHA'), '@recommended' => $this->t('recommended'))), 'moderate' => t('Retain the post for manual moderation'), 'binary' => t('Accept the post')), '#required' => $entity->getProtectionMode() == FormInterface::MOLLOM_MODE_ANALYSIS, '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS), '[name="checks[spam]"]' => array('checked' => TRUE))));
     // Only possible for forms supporting moderation of unpublished posts.
     $form['unsure']['moderate']['#access'] = !empty($mollom_form['moderation callback']);
     $form['discard'] = array('#type' => 'radios', '#title' => t('When text analysis identifies spam'), '#default_value' => $entity->getDiscard(), '#options' => array(1 => t('@option <em>(@recommended)</em>', array('@option' => t('Discard the post'), '@recommended' => $this->t('recommended'))), 0 => t('Retain the post for manual moderation')), '#required' => $entity->getProtectionMode() == FormInterface::MOLLOM_MODE_ANALYSIS, '#states' => array('visible' => array('[name="mode"]' => array('value' => (string) FormInterface::MOLLOM_MODE_ANALYSIS), '[name="checks[spam]"]' => array('checked' => TRUE))));
     // Return the form.
     return $form;
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $this->plugin = $this->entity->getPlugin();
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $this->plugin = $this->shippingQuoteManager->createInstance($this->entity->getPluginId(), $this->entity->getPluginConfiguration());
     return parent::buildForm($form, $form_state);
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\facets\FacetSourceInterface $facet_source */
     $facet_source = $this->getEntity();
     $form['filter_key'] = ['#type' => 'textfield', '#title' => $this->t('Filter key'), '#size' => 20, '#maxlength' => 255, '#default_value' => $facet_source->getFilterKey(), '#description' => $this->t('The key used in the url to identify the facet source.
     When using multiple facet sources you should make sure each facet source has a different filter key.')];
     $url_processors = array();
     $url_processors_description = array();
     foreach ($this->urlProcessorPluginManager->getDefinitions() as $definition) {
         $url_processors[$definition['id']] = $definition['label'];
         $url_processors_description[] = $definition['description'];
     }
     $form['url_processor'] = ['#type' => 'radios', '#title' => $this->t('URL Processor'), '#options' => $url_processors, '#default_value' => $facet_source->getUrlProcessorName(), '#description' => $this->t('The URL Processor defines the url structure used for this facet source.') . '<br />- ' . implode('<br>- ', $url_processors_description)];
     // The parent's form build method will add a save button.
     return parent::buildForm($form, $form_state);
 }
Exemplo n.º 19
0
 /**
  * {@inheritDoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $options = [];
     foreach ($this->manager->getDefinitions() as $plugin_id => $plugin_definition) {
         $options[$plugin_id] = $plugin_definition['label'];
     }
     $form['type'] = ['#type' => 'select', '#title' => $this->t('Pattern type'), '#default_value' => $this->entity->getType(), '#options' => $options, '#required' => TRUE, '#limit_validation_errors' => array(array('type')), '#submit' => array('::submitSelectType'), '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::ajaxReplacePatternForm', 'wrapper' => 'pathauto-pattern', 'method' => 'replace')];
     $form['pattern_container'] = ['#type' => 'container', '#prefix' => '<div id="pathauto-pattern">', '#suffix' => '</div>'];
     // if there is no type yet, stop here.
     if ($this->entity->getType()) {
         $alias_type = $this->entity->getAliasType();
         $form['pattern_container']['pattern'] = array('#type' => 'textfield', '#title' => 'Path pattern', '#default_value' => $this->entity->getPattern(), '#size' => 65, '#maxlength' => 1280, '#element_validate' => array('token_element_validate', 'pathauto_pattern_validate'), '#after_build' => array('token_element_validate'), '#token_types' => $alias_type->getTokenTypes(), '#min_tokens' => 1);
         // Show the token help relevant to this pattern type.
         $form['pattern_container']['token_help'] = array('#theme' => 'token_tree_link', '#token_types' => $alias_type->getTokenTypes());
         // Expose bundle and language conditions.
         if ($alias_type->getDerivativeId() && ($entity_type = $this->entityTypeManager->getDefinition($alias_type->getDerivativeId()))) {
             $default_bundles = [];
             $default_languages = [];
             foreach ($this->entity->getSelectionConditions() as $condition_id => $condition) {
                 if (in_array($condition->getPluginId(), ['entity_bundle:' . $entity_type->id(), 'node_type'])) {
                     $default_bundles = $condition->getConfiguration()['bundles'];
                 } elseif ($condition->getPluginId() == 'language') {
                     $default_languages = $condition->getConfiguration()['langcodes'];
                 }
             }
             if ($entity_type->hasKey('bundle') && ($bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type->id()))) {
                 $bundle_options = [];
                 foreach ($bundles as $id => $info) {
                     $bundle_options[$id] = $info['label'];
                 }
                 $form['pattern_container']['bundles'] = array('#title' => $entity_type->getBundleLabel(), '#type' => 'checkboxes', '#options' => $bundle_options, '#default_value' => $default_bundles, '#description' => t('Check to which types this pattern should be applied. Leave empty to allow any.'));
             }
             if ($this->languageManager->isMultilingual() && $entity_type->isTranslatable()) {
                 $language_options = [];
                 foreach ($this->languageManager->getLanguages() as $id => $language) {
                     $language_options[$id] = $language->getName();
                 }
                 $form['pattern_container']['languages'] = array('#title' => $this->t('Languages'), '#type' => 'checkboxes', '#options' => $language_options, '#default_value' => $default_languages, '#description' => t('Check to which languages this pattern should be applied. Leave empty to allow any.'));
             }
         }
     }
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $this->entity->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('ID'), '#maxlength' => 255, '#default_value' => $this->entity->id(), '#required' => TRUE, '#disabled' => !$this->entity->isNew(), '#machine_name' => array('exists' => 'Drupal\\pathauto\\Entity\\PathautoPattern::load'));
     $form['status'] = ['#title' => $this->t('Enabled'), '#type' => 'checkbox', '#default_value' => $this->entity->status()];
     return parent::buildForm($form, $form_state);
 }
Exemplo n.º 20
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $entity_type = NULL) {
    $form = parent::buildForm($form, $form_state);

    $flag = $this->entity;

    $form['#flag'] = $flag;
    $form['#flag_name'] = $flag->id;

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#default_value' => $flag->label,
      '#description' => $this->t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (these are customizable, though). Some examples could be <em>Bookmarks</em>, <em>Favorites</em>, or <em>Offensive</em>.'),
      '#maxlength' => 255,
      '#required' => TRUE,
      '#weight' => -3,
    ];

    $form['id'] = [
      '#type' => 'machine_name',
      '#title' => $this->t('Machine name'),
      '#default_value' => $flag->id,
      '#description' => $this->t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
      '#weight' => -2,
      '#machine_name' => [
        'exists' => '\Drupal\flag\Entity\Flag::load',
      ],
      '#disabled' => !$flag->isNew(),
      '#required' => TRUE,
    ];

    $form['global'] = [
      '#type' => 'radios',
      '#title' => $this->t('Scope'),
      '#default_value' => $flag->isGlobal() ? 1 : 0,
      '#options' => array(
        0 => t('Personal'),
        1 => t('Global'),
      ),
      '#weight' => -1,
    ];

    // Add descriptions for each radio button.
    $form['global'][0]['#description'] = $this->t('Each user has individual flags on entities.');
    $form['global'][1]['#description'] = $this->t('The entity is either flagged or not for all users.');

    $form['messages'] = [
      '#type' => 'details',
      '#open' => TRUE,
      '#title' => $this->t('Messages'),
    ];

    $flag_short = $flag->getFlagShortText();
    $form['messages']['flag_short'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Flag link text'),
      '#default_value' => !empty($flag_short) ? $flag_short : $this->t('Flag this item'),
      '#description' => $this->t('The text for the "flag this" link for this flag.'),
      '#required' => TRUE,
    ];

    $form['messages']['flag_long'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Flag link description'),
      '#default_value' => $flag->getFlagLongText(),
      '#description' => $this->t('The description of the "flag this" link. Usually displayed on mouseover.'),
    ];

    $form['messages']['flag_message'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Flagged message'),
      '#default_value' => $flag->getFlagMessage(),
      '#description' => $this->t('Message displayed after flagging content. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
    ];

    $unflag_short = $flag->getUnflagShortText();
    $form['messages']['unflag_short'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Unflag link text'),
      '#default_value' => !empty($unflag_short) ? $unflag_short : $this->t('Unflag this item'),
      '#description' => $this->t('The text for the "unflag this" link for this flag.'),
      '#required' => TRUE,
    ];

    $form['messages']['unflag_long'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Unflag link description'),
      '#default_value' => $flag->getUnflagLongText(),
      '#description' => $this->t('The description of the "unflag this" link. Usually displayed on mouseover.'),
    ];

    $form['messages']['unflag_message'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Unflagged message'),
      '#default_value' => $flag->getUnflagMessage(),
      '#description' => $this->t('Message displayed after content has been unflagged. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
    ];

    $form['access'] = [
      '#type' => 'details',
      '#open' => TRUE,
      '#title' => $this->t('Flag access'),
      '#tree' => FALSE,
      '#weight' => 10,
    ];

    // Switch plugin type in case a different is chosen.

    $flag_type_plugin = $flag->getFlagTypePlugin();
    $flag_type_def = $flag_type_plugin->getPluginDefinition();

    $bundles = $this->bundleInfoService->getBundleInfo($flag_type_def['entity_type']);
    $entity_bundles = [];
    foreach ($bundles as $bundle_id => $bundle_row) {
      $entity_bundles[$bundle_id] = $bundle_row['label'];
    }

    // Flag classes will want to override this form element.
    $form['access']['bundles'] = [
      '#type' => 'checkboxes',
      '#title' => $this->t('Flaggable types'),
      '#options' => $entity_bundles,
      '#default_value' => $flag->getBundles(),
      '#description' => $this->t('Check any bundles that this flag may be used on. Leave empty to apply to all bundles.'),
      '#weight' => 10,
    ];

    $form['access']['unflag_denied_text'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Unflag not allowed text'),
      '#default_value' => $flag->getUnflagDeniedText(),
      '#description' => $this->t('If a user is allowed to flag but not unflag, this text will be displayed after flagging. Often this is the past-tense of the link text, such as "flagged".'),
      '#weight' => -1,
    ];

    $form['display'] = [
      '#type' => 'details',
      '#open' => TRUE,
      '#title' => $this->t('Display options'),
      '#description' => $this->t('Flags are usually controlled through links that allow users to toggle their behavior. You can choose how users interact with flags by changing options here. It is legitimate to have none of the following checkboxes ticked, if, for some reason, you wish <a href="@placement-url">to place the the links on the page yourself</a>.', array('@placement-url' => 'http://drupal.org/node/295383')),
      '#tree' => FALSE,
      '#weight' => 20,
      '#prefix' => '<div id="link-type-settings-wrapper">',
      '#suffix' => '</div>',
      // @todo: Move flag_link_type_options_states() into controller?
      // '#after_build' => array('flag_link_type_options_states'),
    ];

    $form['display']['settings'] = [
      '#type' => 'container',
      '#weight' => 21,
    ];

    $form = $flag_type_plugin->buildConfigurationForm($form, $form_state);

    $form['display']['link_type'] = [
      '#type' => 'radios',
      '#title' => $this->t('Link type'),
      '#options' => $this->actionLinkManager->getAllLinkTypes(),
      // '#after_build' => array('flag_check_link_types'),
      '#default_value' => $flag->getLinkTypePlugin()->getPluginId(),
      // Give this a high weight so additions by the flag classes for entity-
      // specific options go above.
      '#weight' => 18,
      '#attributes' => [
        'class' => ['flag-link-options'],
      ],
      '#required' => TRUE,
      '#ajax' => [
        'callback' => '::updateSelectedPluginType',
        'wrapper' => 'link-type-settings-wrapper',
        'event' => 'change',
        'method' => 'replace',
      ],
    ];
    //debug($flag->getLinkTypePlugin()->getPluginId(), 'default value');
    $form['display']['link_type_submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Update'),
      '#submit' => ['::submitSelectPlugin'],
      '#weight' => 20,
      '#attributes' => ['class' => ['js-hide']],
    ];
    // Add the descriptions to each ratio button element. These attach to the
    // elements when FormAPI expands them.
    $action_link_plugin_defs = $this->actionLinkManager->getDefinitions();
    foreach ($action_link_plugin_defs as $key => $info) {
      $form['display']['link_type'][$key] = [
        '#description' => $info['description'],
        '#executes_submit_callback' => TRUE,
        '#limit_validation_errors' => [['link_type']],
        '#submit' => ['::submitSelectPlugin'],
      ];
    }

    $action_link_plugin = $flag->getLinkTypePlugin();
    $form = $action_link_plugin->buildConfigurationForm($form, $form_state);

    return $form;
  }
 public function buildForm(array $form, FormStateInterface $form_state) {
   $form = parent::buildForm($form, $form_state);
   unset($form['actions']);
   $form['#after_build'] = [];
   return $form;
 }