本文整理汇总了PHP中Drupal\Core\Entity\EntityForm::buildForm方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityForm::buildForm方法的具体用法?PHP EntityForm::buildForm怎么用?PHP EntityForm::buildForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityForm
的用法示例。
在下文中一共展示了EntityForm::buildForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@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);
}
示例2: buildForm
/**
* {@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;
}
示例3: buildForm
/**
* {@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;
}
示例4: buildForm
/**
* {@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);
}
示例5: buildForm
/**
* {@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);
}
示例6: buildForm
/**
* {@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;
}
示例7: buildForm
/**
* {@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;
}
示例8: buildForm
/**
* {@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;
}
示例9: buildForm
/**
* {@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;
}
示例10: buildForm
/**
* 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;
}
示例11: buildForm
/**
* 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;
}
示例12: buildForm
/**
* 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;
}
示例13: buildForm
/**
* 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;
}
示例14: buildForm
/**
* 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;
}
示例15: buildForm
/**
* {@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;
}
}
//.........这里部分代码省略.........