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


PHP FormStateInterface::setCached方法代码示例

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


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

示例1: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     if ($form_state->isRebuilding()) {
         $form_state->setUserInput(array());
     }
     // Initialize
     $storage = $form_state->getStorage();
     if (empty($storage)) {
         $user_input = $form_state->getUserInput();
         if (empty($user_input)) {
             $_SESSION['constructions'] = 0;
         }
         // Put the initial thing into the storage
         $storage = ['thing' => ['title' => 'none', 'value' => '']];
         $form_state->setStorage($storage);
     }
     // Count how often the form is constructed.
     $_SESSION['constructions']++;
     drupal_set_message("Form constructions: " . $_SESSION['constructions']);
     $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => $storage['thing']['title'], '#required' => TRUE);
     $form['value'] = array('#type' => 'textfield', '#title' => 'Value', '#default_value' => $storage['thing']['value'], '#element_validate' => array('::elementValidateValueCached'));
     $form['continue_button'] = array('#type' => 'button', '#value' => 'Reset');
     $form['continue_submit'] = array('#type' => 'submit', '#value' => 'Continue submit', '#submit' => array('::continueSubmitForm'));
     $form['submit'] = array('#type' => 'submit', '#value' => 'Save');
     if (\Drupal::request()->get('cache')) {
         // Manually activate caching, so we can test that the storage keeps working
         // when it's enabled.
         $form_state->setCached();
     }
     if ($this->getRequest()->get('immutable')) {
         $form_state->addBuildInfo('immutable', TRUE);
     }
     return $form;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:37,代码来源:FormTestStorageForm.php

示例2: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($this->getRequest()->get('cache')) {
         // Manually activate caching, so we can test that the storage keeps working
         // when it's enabled.
         $form_state->setCached();
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:FormTestStorageForm.php

示例3: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Test using form cache when re-displaying a form due to validation
     // errors.
     if ($form_state->hasAnyErrors()) {
         $form_state->setCached();
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:FormTestStoragePageCacheForm.php

示例4: submitForm

 /**
  * {@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);
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:12,代码来源:FormTestFormStateDatabaseForm.php

示例5: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#required' => TRUE);
     $form['test_build_id_old'] = array('#type' => 'item', '#title' => 'Old build id', '#markup' => 'No old build id');
     $form['submit'] = array('#type' => 'submit', '#value' => 'Save');
     $form['rebuild'] = array('#type' => 'submit', '#value' => 'Rebuild', '#submit' => array(array($this, 'form_test_storage_page_cache_rebuild')));
     $form['#after_build'] = array(array($this, 'form_test_storage_page_cache_old_build_id'));
     $form_state->setCached();
     return $form;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:13,代码来源:FormTestStoragePageCacheForm.php

示例6: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $object = new Callbacks();
     $form['name'] = array('#type' => 'textfield', '#title' => 'Name', '#default_value' => '', '#element_validate' => array(array($object, 'validateName')));
     $form['submit'] = array('#type' => 'submit', '#value' => 'Save');
     // To simplify this test, enable form caching and use form storage to
     // remember our alteration.
     $form_state->setCached();
     return $form;
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:13,代码来源:FormTestValidateForm.php

示例7: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('name') == 'validate') {
         // Alter the form element.
         $form['name']['#value'] = '#value changed by #validate';
         // Alter the submitted value in $form_state.
         $form_state->setValueForElement($form['name'], 'value changed by setValueForElement() in #validate');
         // Output the element's value from $form_state.
         drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state->getValue('name'))));
         // Trigger a form validation error to see our changes.
         $form_state->setErrorByName('');
         // To simplify this test, enable form caching and use form storage to
         // remember our alteration.
         $form_state->setCached();
     }
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:19,代码来源:FormTestValidateForm.php

示例8: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     /*
      * The #ajax attribute used in the temperature input element defines an ajax
      * callback that will invoke the colorCallback method on this form object.
      * Whenever the temperature element changes, it will invoke this callback
      * and replace the contents of the color_wrapper container with the results of this
      * method call.
      */
     $form['temperature'] = ['#title' => $this->t('Temperature'), '#type' => 'select', '#options' => ['warm' => 'Warm', 'cool' => 'Cool'], '#empty_option' => $this->t('-select'), '#ajax' => ['callback' => '::colorCallback', 'wrapper' => 'color-wrapper']];
     // Disable caching on this form.
     $form_state->setCached(FALSE);
     $form['actions'] = ['#type' => 'actions'];
     // Add a submit button that handles the submission of the form.
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Submit')];
     $form['color_wrapper'] = ['#type' => 'container', '#attributes' => ['id' => 'color-wrapper']];
     return $form;
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:21,代码来源:AjaxDemo.php

示例9: buildForm

 /**
  * @param array $form
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  * @param \Drupal\taxonomy\VocabularyInterface $vocabulary
  * @return array
  */
 public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL, $parents = array())
 {
     // Cache form state so that we keep the parents in the modal dialog.
     // For non modals (non POST request), form state caching on is not allowed.
     // @see FormState::setCached()
     if ($this->getRequest()->getMethod() == 'POST') {
         $form_state->setCached(TRUE);
     }
     $form['voc'] = array('#type' => 'value', '#value' => $taxonomy_vocabulary);
     $form['parents']['#tree'] = TRUE;
     foreach ($parents as $p) {
         $form['parents'][$p] = array('#type' => 'value', '#value' => $p);
     }
     $description = $this->t("If you have selected one or more terms in the tree view, the new terms are automatically children of those.");
     $form['help'] = array('#markup' => $description);
     $form['mass_add'] = array('#type' => 'textarea', '#title' => $this->t('Terms'), '#description' => $this->t("One term per line. Child terms can be prefixed with a\n        dash '-' (one dash per hierarchy level). Terms that should not become\n        child terms and start with a dash need to be wrapped in double quotes.\n        <br />Example:<br />\n        animals<br />\n        -canine<br />\n        --dog<br />\n        --wolf<br />\n        -feline<br />\n        --cat"), '#rows' => 10, '#required' => TRUE);
     $form['add'] = array('#type' => 'submit', '#value' => $this->t('Add'));
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:25,代码来源:AddTermsToVocabularyForm.php

示例10: buildForm

 /**
  * {@inheritdoc}
  *
  * @param \Drupal\filter\Entity\FilterFormat $filter_format
  *   The filter format for which this dialog corresponds.
  */
 public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL)
 {
     // This form is special, in that the default values do not come from the
     // server side, but from the client side, from a text editor. We must cache
     // this data in form state, because when the form is rebuilt, we will be
     // receiving values from the form, instead of the values from the text
     // editor. If we don't cache it, this data will be lost.
     if (isset($form_state->getUserInput()['editor_object'])) {
         // By convention, the data that the text editor sends to any dialog is in
         // the 'editor_object' key. And the image dialog for text editors expects
         // that data to be the attributes for an <img> element.
         $file_element = $form_state->getUserInput()['editor_object'];
         $form_state->set('file_element', $file_element);
         $form_state->setCached(TRUE);
     } else {
         // Retrieve the image element's attributes from form state.
         $file_element = $form_state->get('file_element') ?: [];
     }
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'editor/drupal.editor.dialog';
     $form['#prefix'] = '<div id="editor-file-dialog-form">';
     $form['#suffix'] = '</div>';
     // Load dialog settings.
     $editor = editor_load($filter_format->id());
     $file_upload = $editor->getThirdPartySettings('editor_file');
     $max_filesize = min(Bytes::toInt($file_upload['max_size']), file_upload_max_size());
     $existing_file = isset($file_element['data-entity-uuid']) ? \Drupal::entityManager()->loadEntityByUuid('file', $file_element['data-entity-uuid']) : NULL;
     $fid = $existing_file ? $existing_file->id() : NULL;
     $form['fid'] = array('#title' => $this->t('File'), '#type' => 'managed_file', '#upload_location' => $file_upload['scheme'] . '://' . $file_upload['directory'], '#default_value' => $fid ? array($fid) : NULL, '#upload_validators' => array('file_validate_extensions' => !empty($file_upload['extensions']) ? array($file_upload['extensions']) : array('txt'), 'file_validate_size' => array($max_filesize)), '#required' => TRUE);
     $form['attributes']['href'] = array('#title' => $this->t('URL'), '#type' => 'textfield', '#default_value' => isset($file_element['href']) ? $file_element['href'] : '', '#maxlength' => 2048, '#required' => TRUE);
     if ($file_upload['status']) {
         $form['attributes']['href']['#access'] = FALSE;
         $form['attributes']['href']['#required'] = FALSE;
     } else {
         $form['fid']['#access'] = FALSE;
         $form['fid']['#required'] = FALSE;
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['save_modal'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#submit' => array(), '#ajax' => array('callback' => '::submitForm', 'event' => 'click'));
     return $form;
 }
开发者ID:pulibrary,项目名称:recap,代码行数:47,代码来源:EditorFileDialog.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL, $selected_terms = array())
 {
     if (empty($selected_terms)) {
         $form['info'] = array('#markup' => $this->t('Please select the terms you want to export.'));
         return $form;
     }
     // Cache form state so that we keep the parents in the modal dialog.
     $form_state->setCached(TRUE);
     $form['voc'] = array('#type' => 'value', '#value' => $taxonomy_vocabulary);
     $form['selected_terms']['#tree'] = TRUE;
     $items = array();
     foreach ($selected_terms as $t) {
         $term = $this->termStorage->load($t);
         $items[] = $term->getName();
         $form['selected_terms'][$t] = array('#type' => 'value', '#value' => $t);
     }
     $form['terms'] = array('#theme' => 'item_list', '#items' => $items, '#title' => $this->t('Selected terms for export:'));
     $form['download_csv'] = array('#type' => 'submit', '#value' => $this->t('Download CSV'));
     $form['export'] = array('#type' => 'submit', '#value' => $this->t('Export'));
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:24,代码来源:ExportTermsForm.php

示例12: buildForm

 public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL, $selected_terms = array())
 {
     if (empty($selected_terms)) {
         $form['info'] = array('#markup' => $this->t('Please select the terms you want to move.'));
         return $form;
     }
     // Cache form state so that we keep the parents in the modal dialog.
     $form_state->setCached(TRUE);
     $form['voc'] = array('#type' => 'value', '#value' => $taxonomy_vocabulary);
     $form['selected_terms']['#tree'] = TRUE;
     $items = array();
     foreach ($selected_terms as $t) {
         $term = $this->termStorage->load($t);
         $items[] = $term->getName();
         $form['selected_terms'][$t] = array('#type' => 'value', '#value' => $t);
     }
     $form['terms'] = array('#theme' => 'item_list', '#items' => $items, '#title' => $this->t('Selected terms to move:'));
     // @todo Add autocomplete to select/add parent term.
     $form['keep_old_parents'] = array('#type' => 'checkbox', '#title' => $this->t('Keep old parents and add new ones (multi-parent). Otherwise old parents get replaced.'));
     $form['delete'] = array('#type' => 'submit', '#value' => $this->t('Move'));
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:22,代码来源:MoveTermsForm.php

示例13: processAjaxForm

 /**
  * Form element processing handler for the #ajax form property.
  *
  * This method is useful for non-input elements that can be used in and
  * outside the context of a form.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param array $complete_form
  *   The complete form structure.
  *
  * @return array
  *   The processed element.
  *
  * @see self::preRenderAjaxForm()
  */
 public static function processAjaxForm(&$element, FormStateInterface $form_state, &$complete_form)
 {
     $element = static::preRenderAjaxForm($element);
     // If the element was processed as an #ajax element, and a custom URL was
     // provided, set the form to be cached.
     if (!empty($element['#ajax_processed']) && !empty($element['#ajax']['url'])) {
         $form_state->setCached();
     }
     return $element;
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:28,代码来源:RenderElement.php

示例14: testSetCachedWithLogicException

 /**
  * @covers ::setCached
  *
  * @dataProvider providerSingleBooleanArgument
  *
  * @param bool $cache
  *
  * @expectedException \LogicException
  */
 public function testSetCachedWithLogicException($cache)
 {
     $this->decoratedFormState->setCached($cache)->willThrow(\LogicException::class);
     $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setCached($cache));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:14,代码来源:FormStateDecoratorBaseTest.php

示例15: setCached

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


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