当前位置: 首页>>代码示例>>PHP>>正文


PHP FormStateInterface::unsetValue方法代码示例

本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::unsetValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::unsetValue方法的具体用法?PHP FormStateInterface::unsetValue怎么用?PHP FormStateInterface::unsetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Form\FormStateInterface的用法示例。


在下文中一共展示了FormStateInterface::unsetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: removeItemSubmit

 /**
  * Submit callback for remove buttons.
  *
  * @param array $form
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  */
 public static function removeItemSubmit(array &$form, FormStateInterface $form_state)
 {
     $triggering_element = $form_state->getTriggeringElement();
     // Remove weight of entity being removed.
     $form_state->unsetValue(['selected', $triggering_element['#attributes']['data-remove-entity']]);
     // Remove entity itself.
     $selected_entities =& $form_state->get(['entity_browser', 'selected_entities']);
     unset($selected_entities[$triggering_element['#attributes']['data-row-id']]);
     static::saveNewOrder($form_state);
     $form_state->setRebuild();
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:17,代码来源:MultiStepDisplay.php

示例2: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_connection_settings = $form_state->getValue('connection_settings');
     switch ($form_state->getTriggeringElement()['#name']) {
         case 'process_updates':
             // Save the connection settings to the DB.
             $filetransfer_backend = $form_connection_settings['authorize_filetransfer_default'];
             // If the database is available then try to save our settings. We have
             // to make sure it is available since this code could potentially (will
             // likely) be called during the installation process, before the
             // database is set up.
             try {
                 $connection_settings = array();
                 foreach ($form_connection_settings[$filetransfer_backend] as $key => $value) {
                     // We do *not* want to store passwords in the database, unless the
                     // backend explicitly says so via the magic #filetransfer_save form
                     // property. Otherwise, we store everything that's not explicitly
                     // marked with #filetransfer_save set to FALSE.
                     if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) {
                         if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') {
                             $connection_settings[$key] = $value;
                         }
                     } elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) {
                         $connection_settings[$key] = $value;
                     }
                 }
                 // Set this one as the default authorize method.
                 $this->config('system.authorize')->set('filetransfer_default', $filetransfer_backend);
                 // Save the connection settings minus the password.
                 $this->config('system.authorize')->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
                 $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]);
                 // Now run the operation.
                 $this->runOperation($filetransfer);
             } catch (\Exception $e) {
                 // If there is no database available, we don't care and just skip
                 // this part entirely.
             }
             break;
         case 'enter_connection_settings':
             $form_state->setRebuild();
             break;
         case 'change_connection_type':
             $form_state->setRebuild();
             $form_state->unsetValue(array('connection_settings', 'authorize_filetransfer_default'));
             break;
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:50,代码来源:FileTransferAuthorizeForm.php

示例3: save

 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     if (!$form_state->hasValue('context')) {
         $form_state->setValue('context', xmlsitemap_get_current_context());
     }
     if ($form_state->hasValue(['context', 'language'])) {
         $language = $form_state->getValue(['context', 'language']);
         if ($language == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
             $form_state->unsetValue(['context', 'language']);
         }
     }
     $context = $form_state->getValue('context');
     $this->entity->context = $context;
     $this->entity->label = $form_state->getValue('label');
     $this->entity->id = xmlsitemap_sitemap_get_context_hash($context);
     try {
         $status = $this->entity->save();
         if ($status == SAVED_NEW) {
             drupal_set_message($this->t('Saved the %label sitemap.', array('%label' => $this->entity->label())));
         } else {
             if ($status == SAVED_UPDATED) {
                 drupal_set_message($this->t('Updated the %label sitemap.', array('%label' => $this->entity->label())));
             }
         }
     } catch (EntityStorageException $ex) {
         drupal_set_message($this->t('There is another sitemap saved with the same context.'), 'error');
     }
     $form_state->setRedirect('xmlsitemap.admin_search');
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:32,代码来源:XmlSitemapForm.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
     $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
     $widgets = [];
     foreach ($this->widgetManager->getDefinitions() as $plugin_id => $plugin_definition) {
         $widgets[$plugin_id] = $plugin_definition['label'];
     }
     $default_widgets = [];
     foreach ($entity_browser->getWidgets() as $widget) {
         /** @var \Drupal\entity_browser\WidgetInterface $widget */
         $default_widgets[] = $widget->id();
     }
     $form['widget'] = ['#type' => 'select', '#title' => $this->t('Add widget plugin'), '#options' => ['_none_' => '- ' . $this->t('Select a widget to add it') . ' -'] + $widgets, '#ajax' => ['callback' => [get_class($this), 'tableUpdatedAjaxCallback'], 'wrapper' => 'widgets', 'event' => 'change'], '#executes_submit_callback' => TRUE, '#submit' => [[get_class($this), 'submitAddWidget']], '#limit_validation_errors' => [['widget']]];
     $form_state->unsetValue('widget');
     $form['widgets'] = ['#type' => 'container', '#attributes' => ['id' => 'widgets']];
     $form['widgets']['table'] = ['#type' => 'table', '#header' => [$this->t('Form'), $this->t('Operations'), $this->t('Actions'), $this->t('Weight')], '#empty' => $this->t('There are no widgets.'), '#tabledrag' => [['action' => 'order', 'relationship' => 'sibling', 'group' => 'variant-weight']]];
     /** @var \Drupal\entity_browser\WidgetInterface $widget */
     foreach ($entity_browser->getWidgets() as $uuid => $widget) {
         $row = ['#attributes' => ['class' => ['draggable']]];
         $row['label'] = ['#type' => 'textfield', '#default_value' => $widget->label(), '#title' => $this->t('Label')];
         $row['form'] = [];
         $row['form'] = $widget->buildConfigurationForm($row['form'], $form_state);
         $row['remove'] = ['#type' => 'submit', '#value' => $this->t('Delete'), '#name' => 'remove' . $uuid, '#ajax' => ['callback' => [get_class($this), 'tableUpdatedAjaxCallback'], 'wrapper' => 'widgets', 'event' => 'click'], '#executes_submit_callback' => TRUE, '#submit' => [[get_class($this), 'submitDeleteWidget']], '#arguments' => $uuid];
         $row['weight'] = ['#type' => 'weight', '#default_value' => $widget->getWeight(), '#title' => $this->t('Weight for @widget widget', ['@widget' => $widget->label()]), '#title_display' => 'invisible', '#attributes' => ['class' => ['variant-weight']]];
         $form['widgets']['table'][$uuid] = $row;
     }
     return $form;
 }
开发者ID:jepster,项目名称:GaiaD8,代码行数:32,代码来源:WidgetsConfig.php

示例5: copyFormValuesToEntity

 /**
  * {@inheritdoc}
  */
 protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     // Variants will be handled independently.
     $variants = $form_state->getValue('variants');
     $form_state->unsetValue('variants');
     parent::copyFormValuesToEntity($entity, $form, $form_state);
     $form_state->setValue('variants', $variants);
 }
开发者ID:ns-oxit-study,项目名称:drupal-8-training,代码行数:11,代码来源:PageEditForm.php

示例6: view

 /**
  * {@inheritdoc}
  */
 public function view(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     $user = \Drupal::currentUser();
     $pane = $this->pluginDefinition['id'];
     $source = $this->sourcePaneId();
     $contents['#description'] = $this->getDescription();
     if ($source != $pane) {
         $contents['copy_address'] = array('#type' => 'checkbox', '#title' => $this->getCopyAddressText(), '#default_value' => $this->configuration['default_same_address'], '#ajax' => array('callback' => array($this, 'ajaxRender'), 'wrapper' => $pane . '-address-pane', 'progress' => array('type' => 'throbber')));
     }
     if ($user->isAuthenticated() && ($addresses = uc_select_addresses($user->id(), $pane))) {
         $contents['select_address'] = array('#type' => 'select', '#title' => t('Saved addresses'), '#options' => $addresses['#options'], '#ajax' => array('callback' => array($this, 'ajaxRender'), 'wrapper' => $pane . '-address-pane', 'progress' => array('type' => 'throbber')), '#states' => array('invisible' => array('input[name="panes[' . $pane . '][copy_address]"]' => array('checked' => TRUE))));
     }
     $contents['address'] = array('#type' => 'uc_address', '#default_value' => $order->getAddress($pane), '#prefix' => '<div id="' . $pane . '-address-pane">', '#suffix' => '</div>');
     if ($form_state->hasValue(['panes', $pane, 'copy_address'])) {
         $contents['address']['#hidden'] = !$form_state->isValueEmpty(['panes', $pane, 'copy_address']);
     } elseif (isset($contents['copy_address'])) {
         $contents['address']['#hidden'] = $this->configuration['default_same_address'];
     }
     if ($element = $form_state->getTriggeringElement()) {
         $input = $form_state->getUserInput();
         if ($element['#name'] == "panes[{$pane}][copy_address]") {
             $address =& $form_state->getValue(['panes', $source]);
             foreach ($address as $field => $value) {
                 if (substr($field, 0, strlen($source)) == $source) {
                     $field = str_replace($source, $pane, $field);
                     $input['panes'][$pane][$field] = $value;
                     $order->{$field} = $value;
                 }
             }
         }
         if ($element['#name'] == "panes[{$pane}][select_address]") {
             $address = $addresses[$element['#value']];
             foreach ($address as $field => $value) {
                 $input['panes'][$pane][$pane . '_' . $field] = $value;
                 $order->{$pane . '_' . $field} = $value;
             }
         }
         $form_state->setUserInput($input);
         // Forget any previous Ajax submissions, as we send new default values.
         $form_state->unsetValue('uc_address');
     }
     return $contents;
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:46,代码来源:AddressPaneBase.php

示例7: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     if ($values['smtp_on'] == 1 && $values['smtp_host'] == '') {
         $form_state->setErrorByName('smtp_host', $this->t('You must enter an SMTP server address.'));
     }
     if ($values['smtp_on'] == 1 && $values['smtp_port'] == '') {
         $form_state->setErrorByName('smtp_port', $this->t('You must enter an SMTP port number.'));
     }
     if ($values['smtp_from'] && !valid_email_address($values['smtp_from'])) {
         $form_state->setErrorByName('smtp_from', $this->t('The provided from e-mail address is not valid.'));
     }
     if ($values['smtp_test_address'] && !valid_email_address($values['smtp_test_address'])) {
         $form_state->setErrorByName('smtp_test_address', $this->t('The provided test e-mail address is not valid.'));
     }
     // If username is set empty, we must set both username/password empty as well.
     if (empty($values['smtp_username'])) {
         $values['smtp_password'] = '';
     } elseif (empty($values['smtp_password'])) {
         $form_state->unsetValue('smtp_password');
     }
 }
开发者ID:neeravbm,项目名称:shippi,代码行数:25,代码来源:SMTPConfigForm.php

示例8: testUnsetValue

 /**
  * @covers ::unsetValue
  */
 public function testUnsetValue()
 {
     $key = 'FOO';
     $this->decoratedFormState->unsetValue($key)->shouldBeCalled();
     $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->unsetValue($key));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:9,代码来源:FormStateDecoratorBaseTest.php

示例9: blockSubmit

 /**
  * {@inheritdoc}
  */
 public function blockSubmit($form, FormStateInterface $form_state)
 {
     if (!$form_state->isValueEmpty('views_label_checkbox')) {
         $this->configuration['views_label'] = $form_state->getValue('views_label');
     } else {
         $this->configuration['views_label'] = '';
     }
     $form_state->unsetValue('views_label_checkbox');
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:12,代码来源:ViewsBlockBase.php

示例10: validateConfigurationForm

 /**
  * {@inheritdoc}
  *
  * Most block plugins should not override this method. To add validation
  * for a specific block type, override BlockBase::blockValidate().
  *
  * @see \Drupal\Core\Block\BlockBase::blockValidate()
  */
 public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     // Remove the admin_label form item element value so it will not persist.
     $form_state->unsetValue('admin_label');
     // Transform the #type = checkboxes value to a numerically indexed array.
     $contexts = $form_state->getValue(array('cache', 'contexts'));
     $form_state->setValue(array('cache', 'contexts'), array_values(array_filter($contexts)));
     $this->blockValidate($form, $form_state);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:17,代码来源:BlockBase.php

示例11: unsetValue

 /**
  * {@inheritdoc}
  */
 public function unsetValue($key)
 {
     $this->decoratedFormState->unsetValue($key);
     return $this;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:8,代码来源:FormStateDecoratorBase.php

示例12: validateForm

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValues();

    if ($values['smtp_on'] == 1 && $values['smtp_host'] == '') {
      $form_state->setErrorByName('smtp_host', $this->t('You must enter an SMTP server address.'));
    }

    if ($values['smtp_on'] == 1 && $values['smtp_port'] == '') {
      $form_state->setErrorByName('smtp_port', $this->t('You must enter an SMTP port number.'));
    }

    if ($values['smtp_from'] && !valid_email_address($values['smtp_from'])) {
      $form_state->setErrorByName('smtp_from', $this->t('The provided from e-mail address is not valid.'));
    }

    if ($values['smtp_test_address'] && !valid_email_address($values['smtp_test_address'])) {
      $form_state->setErrorByName('smtp_test_address', $this->t('The provided test e-mail address is not valid.'));
    }

    // If username is set empty, we must set both username/password empty as well.
    if (empty($values['smtp_username'])) {
      $values['smtp_password'] = '';
    }
    // A little hack. When form is presented, the password is not shown (Drupal way of doing).
    // So, if user submits the form without changing the password, we must prevent it from being reset.
    elseif (empty($values['smtp_password'])) {
      $form_state->unsetValue('smtp_password');
    }
  }
开发者ID:ashzadeh,项目名称:afbs-ang,代码行数:32,代码来源:SMTPConfigForm.php

示例13: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $form['xmlsitemap']['#entity'];
     $bundle = $form['xmlsitemap']['#bundle'];
     // Handle new bundles by fetching the proper bundle key value from the form
     // state values.
     if (empty($bundle)) {
         $entity_info = $form['xmlsitemap']['#entity_info'];
         if (isset($entity_info['bundle keys']['bundle'])) {
             $bundle_key = $entity_info['bundle keys']['bundle'];
             if ($form_state->hasValue($bundle_key)) {
                 $bundle = $form_state->getValue($bundle_key);
                 $form['xmlsitemap']['#bundle'] = $bundle;
             }
         }
     }
     $xmlsitemap = $form_state->getValue('xmlsitemap');
     xmlsitemap_link_bundle_settings_save($this->entity_type, $this->bundle_type, $xmlsitemap, TRUE);
     $entity_info = $form['xmlsitemap']['#entity_info'];
     if (!empty($form['xmlsitemap']['#show_message'])) {
         drupal_set_message($this->t('XML sitemap settings for the %bundle have been saved.', array('%bundle' => $entity_info['bundles'][$bundle]['label'])));
     }
     // Unset the form values since we have already saved the bundle settings and
     // we don't want these values to get saved as configuration, depending on how
     // the form saves the form values.
     $form_state->unsetValue('xmlsitemap');
     parent::submitForm($form, $form_state);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:31,代码来源:XmlSitemapLinkBundleSettingsForm.php

示例14: validate

 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     // Only validate on edit.
     if ($form_state->hasValue('keyed_mappings')) {
         // Check if another breakpoint group is selected.
         if ($form_state->getValue('breakpointGroup') != $form_state->getCompleteForm()['breakpointGroup']['#default_value']) {
             // Remove the mappings since the breakpoint ID has changed.
             $form_state->unsetValue('keyed_mappings');
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:ResponsiveImageMappingForm.php

示例15: blockSubmit

 /**
  * Handles form submission for the views block configuration form.
  *
  * @param \Drupal\views\Plugin\Block\ViewsBlock $block
  *   The ViewsBlock plugin.
  * @param array $form
  *   The form definition array for the full block configuration form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * * @see \Drupal\views\Plugin\Block\ViewsBlock::blockSubmit()
  */
 public function blockSubmit(ViewsBlock $block, $form, FormStateInterface $form_state)
 {
     if ($items_per_page = $form_state->getValue(array('override', 'items_per_page'))) {
         $block->setConfigurationValue('items_per_page', $items_per_page);
     }
     $form_state->unsetValue(array('override', 'items_per_page'));
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:19,代码来源:Block.php


注:本文中的Drupal\Core\Form\FormStateInterface::unsetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。