Example #1
1
 /**
  * Form element validation handler for 'name' in form_test_validate_form().
  */
 public function validateName(&$element, FormStateInterface $form_state)
 {
     $triggered = FALSE;
     if ($form_state->getValue('name') == 'element_validate') {
         // Alter the form element.
         $element['#value'] = '#value changed by #element_validate';
         // Alter the submitted value in $form_state.
         $form_state->setValueForElement($element, 'value changed by setValueForElement() in #element_validate');
         $triggered = TRUE;
     }
     if ($form_state->getValue('name') == 'element_validate_access') {
         $form_state->set('form_test_name', $form_state->getValue('name'));
         // Alter the form element.
         $element['#access'] = FALSE;
         $triggered = TRUE;
     } elseif ($form_state->has('form_test_name')) {
         // To simplify this test, just take over the element's value into $form_state.
         $form_state->setValueForElement($element, $form_state->get('form_test_name'));
         $triggered = TRUE;
     }
     if ($triggered) {
         // Output the element's value from $form_state.
         drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
         // Trigger a form validation error to see our changes.
         $form_state->setErrorByName('');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $values['default'] = (bool) $values['default'];
     $values['roles'] = array_values(array_filter($values['roles']));
     $form_state->set('values', $values);
     parent::submitConfigurationForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getTriggeringElement()['#name'] == 'select_id_submit') {
         $form_state->set('default_type', $form_state->getValue('id'));
         $form_state->setRebuild();
     } else {
         parent::submitForm($form, $form_state);
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->set('notify_emails', []);
     if (!$form_state->isValueEmpty('update_notify_emails')) {
         $valid = array();
         $invalid = array();
         foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
             $email = trim($email);
             if (!empty($email)) {
                 if ($this->emailValidator->isValid($email)) {
                     $valid[] = $email;
                 } else {
                     $invalid[] = $email;
                 }
             }
         }
         if (empty($invalid)) {
             $form_state->set('notify_emails', $valid);
         } elseif (count($invalid) == 1) {
             $form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
         } else {
             $form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
         }
     }
     parent::validateForm($form, $form_state);
 }
  public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $mode = 'independent', $bundle = '') {
    $form_state->set('target_entity_type_id', $entity_type_id);
    $form_state->set('target_bundle', $bundle);
    $this->entity->setUpdateEntityType($entity_type_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);
 }
 public function buildFieldsForm(array &$form, FormStateInterface $form_state)
 {
     if (!$form_state->has('fields')) {
         $form_state->set('fields', $this->configuration['fields']);
     }
     $form_state_fields = $form_state->get('fields');
     // Check if we need to add a new field, or remove one.
     $triggering_element = $form_state->getTriggeringElement();
     if (isset($triggering_element['#name'])) {
         drupal_set_message(t('Changes in this form will not be saved until the %button button at the form bottom is clicked.', array('%button' => t('Save'))), 'warning');
         $button_name = $triggering_element['#name'];
         if ($button_name == 'add_aggregation_field') {
             // Increment $i until the corresponding field is not set, then create
             // the field with that number as suffix.
             for ($i = 1; isset($form_state_fields['search_api_aggregation_' . $i]); ++$i) {
             }
             $form_state_fields['search_api_aggregation_' . $i] = array('label' => '', 'type' => 'union', 'fields' => array());
         } else {
             // Get the field ID from the button name.
             $field_id = substr($button_name, 25);
             unset($form_state_fields[$field_id]);
         }
         $form_state->set('fields', $form_state_fields);
     }
     // Get index type descriptions.
     $type_descriptions = $this->getTypeDescriptions();
     $types = $this->getTypes();
     // Get the available properties for this index.
     $field_options = array('#type' => 'checkboxes', '#title' => $this->t('Contained fields'), '#options' => array(), '#attributes' => array('class' => array('search-api-checkboxes-list')), '#required' => TRUE);
     $datasource_labels = $this->getDatasourceLabelPrefixes();
     $properties = $this->getAvailableProperties();
     ksort($properties);
     foreach ($properties as $combined_id => $property) {
         list($datasource_id, $name) = Utility::splitCombinedId($combined_id);
         $field_options['#options'][$combined_id] = $datasource_labels[$datasource_id] . $property->getLabel();
         $field_options[$combined_id] = array('#attributes' => array('title' => $this->t('Machine name: @name', array('@name' => $name))), '#description' => $property->getDescription());
     }
     $form['fields'] = array('#type' => 'container', '#attributes' => array('id' => 'search-api-alter-add-aggregation-field-settings'), '#tree' => TRUE);
     foreach ($form_state_fields as $field_id => $field) {
         $new = !$field['label'];
         $form['fields'][$field_id] = array('#type' => 'details', '#title' => $new ? $this->t('New field') : $field['label'], '#open' => $new);
         $form['fields'][$field_id]['label'] = array('#type' => 'textfield', '#title' => $this->t('New field name'), '#default_value' => $field['label'], '#required' => TRUE);
         $form['fields'][$field_id]['type'] = array('#type' => 'select', '#title' => $this->t('Aggregation type'), '#options' => $types, '#default_value' => $field['type'], '#required' => TRUE);
         $form['fields'][$field_id]['type_descriptions'] = $type_descriptions;
         foreach (array_keys($types) as $type) {
             // @todo This shouldn't rely on undocumented form array structure.
             $form['fields'][$field_id]['type_descriptions'][$type]['#states']['visible'][':input[name="processors[aggregated_field][settings][fields][' . $field_id . '][type]"]']['value'] = $type;
         }
         // @todo Order checked fields first in list?
         $form['fields'][$field_id]['fields'] = $field_options;
         $form['fields'][$field_id]['fields']['#default_value'] = $field['fields'];
         $form['fields'][$field_id]['actions'] = array('#type' => 'actions', 'remove' => array('#type' => 'submit', '#value' => $this->t('Remove field'), '#submit' => array(array($this, 'submitAjaxFieldButton')), '#limit_validation_errors' => array(), '#name' => 'remove_aggregation_field_' . $field_id, '#ajax' => array('callback' => array($this, 'buildAjaxAddFieldButton'), 'wrapper' => 'search-api-alter-add-aggregation-field-settings')));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $event = NULL)
 {
     $entity = clone $route_match->getParameter($event);
     $form_state->set('event', $entity);
     $display = entity_get_form_display($entity->getEntityTypeId(), $entity->bundle(), 'rng_event');
     $form_state->set('form_display', $display);
     $form['event'] = ['#weight' => 0];
     $display->buildForm($entity, $form['event'], $form_state);
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => t('Save'), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['title'] = array('#type' => 'textfield', '#title' => 'title', '#default_value' => 'DEFAULT', '#required' => TRUE);
     $form_state->set('value', 'State persisted.');
     $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     // Trick inline_entity_form_form_alter() into attaching the handlers,
     // WidgetSubmit will be needed once extractFormValues fills the $form_state.
     $parents = array_merge($element['#field_parents'], [$items->getName()]);
     $ief_id = sha1(implode('-', $parents));
     $form_state->set(['inline_entity_form', $ief_id], []);
     $element['#type'] = 'fieldset';
     $item = $items->get($delta);
     if ($item->target_id && !$item->entity) {
         $element['warning']['#markup'] = $this->t('Unable to load the referenced entity.');
         return $element;
     }
     $entity = $item->entity;
     $op = $entity ? 'edit' : 'add';
     $language = $items->getParent()->getValue()->language()->getId();
     $parents = array_merge($element['#field_parents'], [$items->getName(), $delta, 'inline_entity_form']);
     $bundle = reset($this->getFieldSetting('handler_settings')['target_bundles']);
     $element['inline_entity_form'] = $this->getInlineEntityForm($op, $bundle, $language, $delta, $parents, $entity);
     if ($op == 'edit') {
         /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
         if (!$entity->access('update')) {
             // The user isn't allowed to edit the entity, but still needs to see
             // it, to be able to reorder values.
             $element['entity_label'] = ['#type' => 'markup', '#markup' => $entity->label()];
             // Hide the inline form. getInlineEntityForm() still needed to be
             // called because otherwise the field re-ordering doesn't work.
             $element['inline_entity_form']['#access'] = FALSE;
         }
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $allowed_selectable_plugin_ids = NULL, $plugin_id = NULL, $tree = FALSE)
 {
     if ($form_state->has('plugin_selector')) {
         $plugin_selector = $form_state->get('plugin_selector');
     } else {
         $selectable_plugin_discovery = new LimitedPluginDiscoveryDecorator($this->selectablePluginType->getPluginManager());
         $selectable_plugin_discovery->setDiscoveryLimit(explode(',', $allowed_selectable_plugin_ids));
         $selectable_plugin_manager = new PluginManagerDecorator($this->selectablePluginType->getPluginManager(), $selectable_plugin_discovery);
         $plugin_selector = $this->pluginSelectorManager->createInstance($plugin_id);
         $plugin_selector->setSelectablePluginType($this->selectablePluginType);
         $plugin_selector->setSelectablePluginDiscovery($selectable_plugin_manager);
         $plugin_selector->setSelectablePluginFactory($selectable_plugin_manager);
         $plugin_selector->setRequired();
         $form_state->set('plugin_selector', $plugin_selector);
     }
     $form['plugin'] = $plugin_selector->buildSelectorForm([], $form_state);
     // Nest the selector in a tree if that's required.
     if ($tree) {
         $form['tree'] = array('#tree' => TRUE);
         $form['tree']['plugin'] = $form['plugin'];
         unset($form['plugin']);
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageVariantInterface $page_variant = NULL, $block_id = NULL)
 {
     $this->pageVariant = $page_variant;
     $this->block = $this->prepareBlock($block_id);
     $form_state->set('page_variant_id', $page_variant->id());
     $form_state->set('block_id', $this->block->getConfiguration()['uuid']);
     $form['#tree'] = TRUE;
     $form['settings'] = $this->block->buildConfigurationForm([], $form_state);
     $form['settings']['id'] = ['#type' => 'value', '#value' => $this->block->getPluginId()];
     $form['region'] = ['#title' => $this->t('Region'), '#type' => 'select', '#options' => $this->getVariantPlugin()->getRegionNames(), '#default_value' => $this->getVariantPlugin()->getRegionAssignment($this->block->getConfiguration()['uuid']), '#required' => TRUE];
     if ($this->block instanceof ContextAwarePluginInterface) {
         $form['context_mapping'] = $this->addContextAssignmentElement($this->block, $this->pageVariant->getContexts());
     }
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $entity = $this->entity;
     // Store theme settings in $form_state for use below.
     if (!($theme = $entity->get('theme'))) {
         $theme = $this->config('system.theme')->get('default');
     }
     $form_state->set('block_theme', $theme);
     $form['#tree'] = TRUE;
     $form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state);
     // If creating a new block, calculate a safe default machine name.
     $form['id'] = array('#type' => 'machine_name', '#maxlength' => 64, '#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'), '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity), '#machine_name' => array('exists' => '\\Drupal\\block\\Entity\\Block::load', 'replace_pattern' => '[^a-z0-9_.]+', 'source' => array('settings', 'label')), '#required' => TRUE, '#disabled' => !$entity->isNew());
     // Theme settings.
     if ($entity->get('theme')) {
         $form['theme'] = array('#type' => 'value', '#value' => $theme);
     } else {
         $theme_options = array();
         foreach (list_themes() as $theme_name => $theme_info) {
             if (!empty($theme_info->status)) {
                 $theme_options[$theme_name] = $theme_info->info['name'];
             }
         }
         $form['theme'] = array('#type' => 'select', '#options' => $theme_options, '#title' => t('Theme'), '#default_value' => $theme, '#ajax' => array('callback' => '::themeSwitch', 'wrapper' => 'edit-block-region-wrapper'));
     }
     // Region settings.
     $form['region'] = array('#type' => 'select', '#title' => $this->t('Region'), '#description' => $this->t('Select the region where this block should be displayed.'), '#default_value' => $entity->get('region'), '#empty_value' => BlockInterface::BLOCK_REGION_NONE, '#options' => system_region_list($theme, REGIONS_VISIBLE), '#prefix' => '<div id="edit-block-region-wrapper">', '#suffix' => '</div>');
     $form['#attached']['css'] = array(drupal_get_path('module', 'block') . '/css/block.admin.css');
     return $form;
 }
Example #14
0
 /**
  * @inheritDoc
  */
 public function buildForm(array $form, FormStateInterface $form_state, ContentEntityInterface $entity = NULL)
 {
     /** @var ModerationState $current_state */
     $current_state = $entity->moderation_state->entity;
     $transitions = $this->validation->getValidTransitions($entity, $this->currentUser());
     // Exclude self-transitions.
     $transitions = array_filter($transitions, function (ModerationStateTransition $transition) use($current_state) {
         return $transition->getToState() != $current_state->id();
     });
     $target_states = [];
     /** @var ModerationStateTransition $transition */
     foreach ($transitions as $transition) {
         $target_states[$transition->getToState()] = $transition->label();
     }
     if ($current_state) {
         $form['current'] = ['#type' => 'item', '#title' => $this->t('Status'), '#markup' => $current_state->label()];
     }
     // Persist the entity so we can access it in the submit handler.
     $form_state->set('entity', $entity);
     $form['new_state'] = ['#type' => 'select', '#title' => $this->t('Moderate'), '#options' => $target_states];
     $form['revision_log'] = ['#type' => 'textfield', '#title' => $this->t('Log message'), '#size' => 30];
     $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Apply')];
     $form['#theme'] = ['entity_moderation_form'];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $key = 'payment_reference_element_prototype_payment';
     if ($form_state->has($key)) {
         $prototype_payment = $form_state->get($key);
         /** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
         $payment_type = $prototype_payment->getPaymentType();
     } else {
         $entity_type_id = 'user';
         $bundle = 'user';
         $field_name = 'foobarbaz';
         /** @var \Drupal\payment\Entity\PaymentInterface $prototype_payment */
         $prototype_payment = entity_create('payment', array('bundle' => 'payment_reference'));
         $prototype_payment->setCurrencyCode('EUR')->setOwnerId(2)->setLineItems(Generate::createPaymentLineItems());
         /** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
         $payment_type = $prototype_payment->getPaymentType();
         $payment_type->setEntityTypeId($entity_type_id);
         $payment_type->setBundle($bundle);
         $payment_type->setFieldName($field_name);
         $form_state->set($key, $prototype_payment);
     }
     $form['payment_reference'] = array('#plugin_selector_id' => 'payment_select_list', '#prototype_payment' => $prototype_payment, '#queue_category_id' => $payment_type->getEntityTypeId() . '.' . $payment_type->getBundle() . '.' . $payment_type->getFieldName(), '#queue_owner_id' => 2, '#required' => TRUE, '#title' => 'FooBarBaz', '#type' => 'payment_reference');
     $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
     return $form;
 }
 public function save(array $form, FormStateInterface $form_state) {
   if ($this->entity->getEFormType()->preview_page) {
     $form_state->set('preview_entity', $this->entity);
     $form_state->setRebuild();
   }
   return parent::save($form, $form_state);
 }
Example #17
0
 /**
  * {@inheritdoc]
  */
 public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity_1 = NULL, EntityInterface $entity_2 = NULL)
 {
     // First entity.
     $form_state->set('entity_1', $entity_1);
     $form_display_1 = EntityFormDisplay::collectRenderDisplay($entity_1, 'default');
     $form_state->set('form_display_1', $form_display_1);
     $form_display_1->buildForm($entity_1, $form, $form_state);
     // Second entity.
     $form_state->set('entity_2', $entity_2);
     $form_display_2 = EntityFormDisplay::collectRenderDisplay($entity_2, 'default');
     $form_state->set('form_display_2', $form_display_2);
     $form['entity_2'] = array('#type' => 'details', '#title' => t('Second entity'), '#tree' => TRUE, '#parents' => array('entity_2'), '#weight' => 50);
     $form_display_2->buildForm($entity_2, $form['entity_2'], $form_state);
     $form['save'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 100);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, LanguageInterface $language = NULL)
 {
     if ($language) {
         $form_state->set('langcode', $language->getId());
     }
     return parent::buildForm($form, $form_state);
 }
 /**
  * Process handler for the language_configuration form element.
  */
 public static function processLanguageConfiguration(&$element, FormStateInterface $form_state, &$form)
 {
     $options = isset($element['#options']) ? $element['#options'] : array();
     // Avoid validation failure since we are moving the '#options' key in the
     // nested 'language' select element.
     unset($element['#options']);
     /** @var ContentLanguageSettings $default_config */
     $default_config = $element['#default_value'];
     $element['langcode'] = array('#type' => 'select', '#title' => t('Default language'), '#options' => $options + static::getDefaultOptions(), '#description' => t('Explanation of the language options is found on the <a href="@languages_list_page">languages list page</a>.', array('@languages_list_page' => \Drupal::url('entity.configurable_language.collection'))), '#default_value' => $default_config != NULL ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT);
     $element['language_alterable'] = array('#type' => 'checkbox', '#title' => t('Show language selector on create and edit pages'), '#default_value' => $default_config != NULL ? $default_config->isLanguageAlterable() : FALSE);
     // Add the entity type and bundle information to the form if they are set.
     // They will be used, in the submit handler, to generate the names of the
     // configuration entities that will store the settings and are a way to uniquely
     // identify the entity.
     $language = $form_state->get('language') ?: [];
     $language += array($element['#name'] => array('entity_type' => $element['#entity_information']['entity_type'], 'bundle' => $element['#entity_information']['bundle']));
     $form_state->set('language', $language);
     // Do not add the submit callback for the language content settings page,
     // which is handled separately.
     if ($form['#form_id'] != 'language_content_settings_form') {
         // Determine where to attach the language_configuration element submit
         // handler.
         // @todo Form API: Allow form widgets/sections to declare #submit
         //   handlers.
         $submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';
         if (isset($form['actions'][$submit_name]['#submit']) && array_search('language_configuration_element_submit', $form['actions'][$submit_name]['#submit']) === FALSE) {
             $form['actions'][$submit_name]['#submit'][] = 'language_configuration_element_submit';
         } elseif (array_search('language_configuration_element_submit', $form['#submit']) === FALSE) {
             $form['#submit'][] = 'language_configuration_element_submit';
         }
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, RulesUiHandlerInterface $rules_ui_handler = NULL, $uuid = NULL)
 {
     $this->rulesUiHandler = $rules_ui_handler;
     $this->component = is_object($form_state->get('component')) ? $form_state->get('component') : $this->rulesUiHandler->getComponent();
     $this->uuid = $form_state->get('uuid') ?: $uuid;
     // During form rebuilds, keep track of changes using form state.
     $form_state->set('rules_ui_handler', $this->rulesUiHandler);
     $form_state->set('component', $this->component);
     $form_state->set('uuid', $this->uuid);
     $expression = $this->getEditedExpression($this->component, $form_state);
     if (!$expression) {
         throw new NotFoundHttpException();
     }
     $form_handler = $expression->getFormHandler();
     $form = $form_handler->form($form, $form_state);
     return $form;
 }
 /**
  * Stores a plugin selector in the form state.
  *
  * @param \Drupal\Core\Form\FormStateInterface
  * @param \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  *
  * @return string[]
  *   The form state storage key that contains the plugin selector.
  *
  * @throws \InvalidArgumentException
  */
 protected static function setPluginSelector(FormStateInterface $form_state, PluginSelectorInterface $plugin_selector)
 {
     do {
         $key = [get_class(), mt_rand()];
     } while ($form_state->has($key));
     $form_state->set($key, $plugin_selector);
     return $key;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, RulesUiHandlerInterface $rules_ui_handler = NULL, $uuid = NULL, $expression_id = NULL)
 {
     $this->expressionId = $expression_id;
     $this->uuid = $uuid;
     // When initially adding the expression, we have to initialize the object
     // and add the expression.
     if (!$this->uuid) {
         // Before we add our edited expression to the component's expression,
         // we clone it such that we do not change the source component until
         // the form has been successfully submitted.
         $component = clone $rules_ui_handler->getComponent();
         $this->uuid = $this->getEditedExpression($component)->getUuid();
         $form_state->set('component', $component);
         $form_state->set('uuid', $this->uuid);
     }
     return parent::buildForm($form, $form_state, $rules_ui_handler, $this->uuid);
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function set($property, $value)
 {
     if (isset(self::$inheritedKeys[$property])) {
         $this->mainFormState->set($property, $value);
     } else {
         $this->internalStorage[$property] = $value;
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $json = TRUE)
 {
     $form_state->set('json', $json);
     $form['checkbox_off'] = array('#title' => t('Checkbox off'), '#type' => 'checkboxes', '#options' => array('foo', 'bar', 'baz'));
     $form['checkbox_zero_default'] = array('#title' => t('Zero default'), '#type' => 'checkboxes', '#options' => array('foo', 'bar', 'baz'), '#default_value' => array(0));
     $form['checkbox_string_zero_default'] = array('#title' => t('Zero default (string)'), '#type' => 'checkboxes', '#options' => array('foo', 'bar', 'baz'), '#default_value' => array('0'));
     $form['submit'] = array('#type' => 'submit', '#value' => 'Save');
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->setCached();
     $form_state->setRebuild();
     $database_class = $form_state->get('database_class');
     if ($form_state->get('database') instanceof $database_class) {
         $form_state->set('database_connection_found', TRUE);
     }
 }
 /**
  * {@inheritdoc}
  *
  * @param \Drupal\user\Entity\UserInterface $user
  *   The user account.
  */
 public function buildForm(array $form, FormStateInterface $form_state, UserInterface $user = NULL)
 {
     $form_state->set('user', $user);
     $form['user_form_test_field'] = array('#type' => 'textfield', '#title' => $this->t('Test field'), '#description' => $this->t('A field that would require a correct password to change.'), '#required' => TRUE);
     $form['current_pass'] = array('#type' => 'password', '#title' => $this->t('Current password'), '#size' => 25, '#description' => $this->t('Enter your current password'));
     $form['current_pass_required_values'] = array('#type' => 'value', '#value' => array('user_form_test_field' => $this->t('Test field')));
     $form['#validate'][] = 'user_validate_current_pass';
     $form['submit'] = array('#type' => 'submit', '#value' => $this->t('Test'));
     return $form;
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config_text = $form_state->getValue('config') ?: 'attributes:';
     try {
         $form_state->set('config', Yaml::decode($config_text));
     } catch (InvalidDataTypeException $e) {
         $form_state->setErrorByName('config', $e->getMessage());
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $order = NULL)
 {
     if (!$form_state->has('uc_order')) {
         $form_state->set('uc_order', $order);
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['back'] = array('#type' => 'submit', '#value' => $this->t('Back'), '#submit' => array(array($this, 'back')));
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit order'), '#button_type' => 'primary');
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Don't show the form when batch operations are in progress.
     if ($batch = batch_get() && isset($batch['current_set'])) {
         return array('#theme' => '');
     }
     // Make sure that we validate because this form might be submitted
     // multiple times per page.
     $form_state->setValidationEnforced();
     /** @var \Drupal\views\ViewExecutable $view */
     $view = $form_state->get('view');
     $display =& $form_state->get('display');
     $form_state->setUserInput($view->getExposedInput());
     // Let form plugins know this is for exposed widgets.
     $form_state->set('exposed', TRUE);
     // Check if the form was already created
     if ($cache = $this->exposedFormCache->getForm($view->storage->id(), $view->current_display)) {
         return $cache;
     }
     $form['#info'] = array();
     // Go through each handler and let it generate its exposed widget.
     foreach ($view->display_handler->handlers as $type => $value) {
         /** @var \Drupal\views\Plugin\views\ViewsHandlerInterface $handler */
         foreach ($view->{$type} as $id => $handler) {
             if ($handler->canExpose() && $handler->isExposed()) {
                 // Grouped exposed filters have their own forms.
                 // Instead of render the standard exposed form, a new Select or
                 // Radio form field is rendered with the available groups.
                 // When an user choose an option the selected value is split
                 // into the operator and value that the item represents.
                 if ($handler->isAGroup()) {
                     $handler->groupForm($form, $form_state);
                     $id = $handler->options['group_info']['identifier'];
                 } else {
                     $handler->buildExposedForm($form, $form_state);
                 }
                 if ($info = $handler->exposedInfo()) {
                     $form['#info']["{$type}-{$id}"] = $info;
                 }
             }
         }
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#name' => '', '#type' => 'submit', '#value' => $this->t('Apply'), '#id' => drupal_html_id('edit-submit-' . $view->storage->id()));
     $form['#action'] = _url($view->display_handler->getUrl());
     $form['#theme'] = $view->buildThemeFunctions('views_exposed_form');
     $form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . String::checkPlain($view->storage->id()) . '-' . String::checkPlain($display['id']));
     // $form['#attributes']['class'] = array('views-exposed-form');
     /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */
     $exposed_form_plugin = $form_state->get('exposed_form_plugin');
     $exposed_form_plugin->exposedFormAlter($form, $form_state);
     // Save the form.
     $this->exposedFormCache->setForm($view->storage->id(), $view->current_display, $form);
     return $form;
 }
Example #30
-2
 /**
  * Submit callback: switch a context to data selecor or direct input mode.
  */
 public function switchContextMode(array &$form, FormStateInterface $form_state)
 {
     $element_name = $form_state->getTriggeringElement()['#name'];
     $mode = $form_state->get($element_name);
     $switched_mode = $mode == 'selector' ? 'input' : 'selector';
     $form_state->set($element_name, $switched_mode);
     $form_state->setRebuild();
 }