當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。