本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::disableCache方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::disableCache方法的具体用法?PHP FormStateInterface::disableCache怎么用?PHP FormStateInterface::disableCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::disableCache方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$view = $this->entity;
$form['#prefix'] = '<div id="views-preview-wrapper" class="views-admin clearfix">';
$form['#suffix'] = '</div>';
$form['#id'] = 'views-ui-preview-form';
$form_state->disableCache();
$form['controls']['#attributes'] = array('class' => array('clearfix'));
$form['controls']['title'] = array('#prefix' => '<h2 class="view-preview-form__title">', '#markup' => $this->t('Preview'), '#suffix' => '</h2>');
// Add a checkbox controlling whether or not this display auto-previews.
$form['controls']['live_preview'] = array('#type' => 'checkbox', '#id' => 'edit-displays-live-preview', '#title' => $this->t('Auto preview'), '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'));
// Add the arguments textfield
$form['controls']['view_args'] = array('#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args');
$args = array();
if (!$form_state->isValueEmpty('view_args')) {
$args = explode('/', $form_state->getValue('view_args'));
}
$user_input = $form_state->getUserInput();
if ($form_state->get('show_preview') || !empty($user_input['js'])) {
$form['preview'] = array('#weight' => 110, '#theme_wrappers' => array('container'), '#attributes' => array('id' => 'views-live-preview'), 'preview' => $view->renderPreview($this->displayID, $args));
}
$uri = $view->urlInfo('preview-form');
$uri->setRouteParameter('display_id', $this->displayID);
$form['#action'] = $uri->toString();
return $form;
}
示例2: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$view = $this->entity;
$display_id = $this->displayID;
// Do not allow the form to be cached, because $form_state->get('view') can become
// stale between page requests.
// See views_ui_ajax_get_form() for how this affects #ajax.
// @todo To remove this and allow the form to be cacheable:
// - Change $form_state->get('view') to $form_state->getTemporary()['view'].
// - Add a #process function to initialize $form_state->getTemporary()['view']
// on cached form submissions.
// - Use \Drupal\Core\Form\FormStateInterface::loadInclude().
$form_state->disableCache();
if ($display_id) {
if (!$view->getExecutable()->setDisplay($display_id)) {
$form['#markup'] = $this->t('Invalid display id @display', array('@display' => $display_id));
return $form;
}
}
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'core/jquery.ui.tabs';
$form['#attached']['library'][] = 'core/jquery.ui.dialog';
$form['#attached']['library'][] = 'core/drupal.states';
$form['#attached']['library'][] = 'core/drupal.tabledrag';
$form['#attached']['library'][] = 'views_ui/views_ui.admin';
$form['#attached']['library'][] = 'views_ui/admin.styling';
$form += array('#prefix' => '', '#suffix' => '');
$view_status = $view->status() ? 'enabled' : 'disabled';
$form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
$form['#suffix'] = '</div>' . $form['#suffix'];
$form['#attributes']['class'] = array('form-edit');
if ($view->isLocked()) {
$username = array('#theme' => 'username', '#account' => $this->entityManager->getStorage('user')->load($view->lock->owner));
$lock_message_substitutions = array('@user' => drupal_render($username), '@age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated), ':url' => $view->url('break-lock-form'));
$form['locked'] = array('#type' => 'container', '#attributes' => array('class' => array('view-locked', 'messages', 'messages--warning')), '#children' => $this->t('This view is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $lock_message_substitutions), '#weight' => -10);
} else {
$form['changed'] = array('#type' => 'container', '#attributes' => array('class' => array('view-changed', 'messages', 'messages--warning')), '#children' => $this->t('You have unsaved changes.'), '#weight' => -10);
if (empty($view->changed)) {
$form['changed']['#attributes']['class'][] = 'js-hide';
}
}
$form['displays'] = array('#prefix' => '<h1 class="unit-title clearfix">' . $this->t('Displays') . '</h1>', '#type' => 'container', '#attributes' => array('class' => array('views-displays')));
$form['displays']['top'] = $this->renderDisplayTop($view);
// The rest requires a display to be selected.
if ($display_id) {
$form_state->set('display_id', $display_id);
// The part of the page where editing will take place.
$form['displays']['settings'] = array('#type' => 'container', '#id' => 'edit-display-settings', '#attributes' => array('class' => array('edit-display-settings')));
// Add a text that the display is disabled.
if ($view->getExecutable()->displayHandlers->has($display_id)) {
if (!$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
$form['displays']['settings']['disabled']['#markup'] = $this->t('This display is disabled.');
}
}
// Add the edit display content
$tab_content = $this->getDisplayTab($view);
$tab_content['#theme_wrappers'] = array('container');
$tab_content['#attributes'] = array('class' => array('views-display-tab'));
$tab_content['#id'] = 'views-tab-' . $display_id;
// Mark deleted displays as such.
$display = $view->get('display');
if (!empty($display[$display_id]['deleted'])) {
$tab_content['#attributes']['class'][] = 'views-display-deleted';
}
// Mark disabled displays as such.
if ($view->getExecutable()->displayHandlers->has($display_id) && !$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
$tab_content['#attributes']['class'][] = 'views-display-disabled';
}
$form['displays']['settings']['settings_content'] = array('#type' => 'container', 'tab_content' => $tab_content);
}
return $form;
}
示例3: disableCache
/**
* {@inheritdoc}
*/
public function disableCache()
{
$this->mainFormState->disableCache();
return $this;
}
示例4: ajaxFormWrapper
/**
* Wrapper for handling AJAX forms.
*
* Wrapper around \Drupal\Core\Form\FormBuilderInterface::buildForm() to
* handle some AJAX stuff automatically.
* This makes some assumptions about the client.
*
* @param \Drupal\Core\Form\FormInterface|string $form_class
* The value must be one of the following:
* - The name of a class that implements \Drupal\Core\Form\FormInterface.
* - An instance of a class that implements \Drupal\Core\Form\FormInterface.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\Core\Ajax\AjaxResponse|string|array
* Returns one of three possible values:
* - A \Drupal\Core\Ajax\AjaxResponse object.
* - The rendered form, as a string.
* - A render array with the title in #title and the rendered form in the
* #markup array.
*/
protected function ajaxFormWrapper($form_class, FormStateInterface &$form_state)
{
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
// This won't override settings already in.
if (!$form_state->has('rerender')) {
$form_state->set('rerender', FALSE);
}
$ajax = $form_state->get('ajax');
// Do not overwrite if the redirect has been disabled.
if (!$form_state->isRedirectDisabled()) {
$form_state->disableRedirect($ajax);
}
$form_state->disableCache();
// Builds the form in a render context in order to ensure that cacheable
// metadata is bubbled up.
$render_context = new RenderContext();
$callable = function () use($form_class, &$form_state) {
return \Drupal::formBuilder()->buildForm($form_class, $form_state);
};
$form = $renderer->executeInRenderContext($render_context, $callable);
if (!$render_context->isEmpty()) {
BubbleableMetadata::createFromRenderArray($form)->merge($render_context->pop())->applyTo($form);
}
$output = $renderer->renderRoot($form);
drupal_process_attached($form);
// These forms have the title built in, so set the title here:
$title = $form_state->get('title') ?: '';
if ($ajax && (!$form_state->isExecuted() || $form_state->get('rerender'))) {
// If the form didn't execute and we're using ajax, build up an
// Ajax command list to execute.
$response = new AjaxResponse();
// Attach the library necessary for using the OpenModalDialogCommand and
// set the attachments for this Ajax response.
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$response->setAttachments($form['#attached']);
$display = '';
$status_messages = array('#type' => 'status_messages');
if ($messages = $renderer->renderRoot($status_messages)) {
$display = '<div class="views-messages">' . $messages . '</div>';
}
$display .= $output;
$options = array('dialogClass' => 'views-ui-dialog', 'width' => '75%');
$response->addCommand(new OpenModalDialogCommand($title, $display, $options));
if ($section = $form_state->get('#section')) {
$response->addCommand(new Ajax\HighlightCommand('.' . Html::cleanCssIdentifier($section)));
}
return $response;
}
return $title ? ['#title' => $title, '#markup' => $output] : $output;
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$index = $this->entity;
// Do not allow the form to be cached. See
// \Drupal\views_ui\ViewEditForm::form().
$form_state->disableCache();
if ($index instanceof UnsavedConfigurationInterface && $index->hasChanges()) {
if ($index->isLocked()) {
$form['#disabled'] = TRUE;
$username = array('#theme' => 'username', '#account' => $index->getLockOwner($this->entityTypeManager));
$lock_message_substitutions = array('@user' => $this->getRenderer()->render($username), '@age' => $this->dateFormatter->formatTimeDiffSince($index->getLastUpdated()), ':url' => $index->toUrl('break-lock-form')->toString());
$form['locked'] = array('#type' => 'container', '#attributes' => array('class' => array('index-locked', 'messages', 'messages--warning')), '#children' => $this->t('This index is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $lock_message_substitutions), '#weight' => -10);
}
}
$args['%index'] = $index->label();
$form['#title'] = $this->t('Add fields to index %index', $args);
$form['properties'] = array('#theme' => 'search_api_form_item_list');
$datasources = array('' => NULL);
$datasources += $this->entity->getDatasources();
foreach ($datasources as $datasource) {
$form['properties'][] = $this->getDatasourceListItem($datasource);
}
// Log any unmapped types that were encountered.
if ($this->unmappedFields) {
$unmapped_types = array();
foreach ($this->unmappedFields as $type => $fields) {
$unmapped_types[] = implode(', ', $fields) . ' (' . new FormattableMarkup('type @type', array('@type' => $type)) . ')';
}
$vars['@fields'] = implode('; ', $unmapped_types);
$vars['%index'] = $this->entity->label();
\Drupal::logger('search_api')->warning('Warning while retrieving available fields for index %index: could not find a type mapping for the following fields: @fields.', $vars);
}
$form['actions'] = $this->actionsElement($form, $form_state);
return $form;
}
示例6: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$index = $this->entity;
// Do not allow the form to be cached. See
// \Drupal\views_ui\ViewEditForm::form().
$form_state->disableCache();
if ($index instanceof UnsavedConfigurationInterface && $index->hasChanges()) {
if ($index->isLocked()) {
$form['#disabled'] = TRUE;
$username = array('#theme' => 'username', '#account' => $index->getLockOwner($this->entityTypeManager));
$lock_message_substitutions = array('@user' => $this->getRenderer()->render($username), '@age' => $this->dateFormatter->formatTimeDiffSince($index->getLastUpdated()), ':url' => $index->toUrl('break-lock-form')->toString());
$form['locked'] = array('#type' => 'container', '#attributes' => array('class' => array('index-locked', 'messages', 'messages--warning')), '#children' => $this->t('This index is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $lock_message_substitutions), '#weight' => -10);
} else {
$form['changed'] = array('#type' => 'container', '#attributes' => array('class' => array('index-changed', 'messages', 'messages--warning')), '#children' => $this->t('You have unsaved changes.'), '#weight' => -10);
}
}
// Set an appropriate page title.
$form['#title'] = $this->t('Manage fields for search index %label', array('%label' => $index->label()));
$form['#tree'] = TRUE;
$form['description']['#markup'] = $this->t('<p>The data type of a field determines how it can be used for searching and filtering. The boost is used to give additional weight to certain fields, e.g. titles or tags.</p> <p>Whether detailed field types are supported depends on the type of server this index resides on. In any case, fields of type "Fulltext" will always be fulltext-searchable.</p>');
if ($index->hasValidServer()) {
$form['description']['#markup'] .= '<p>' . $this->t('Check the <a href=":server-url">' . "server's</a> backend class description for details.", array(':server-url' => $index->getServerInstance()->toUrl('canonical')->toString())) . '</p>';
}
if ($fields = $index->getFieldsByDatasource(NULL)) {
$form['_general'] = $this->buildFieldsTable($fields);
$form['_general']['#title'] = $this->t('General');
}
foreach ($index->getDatasources() as $datasource_id => $datasource) {
$fields = $index->getFieldsByDatasource($datasource_id);
$form[$datasource_id] = $this->buildFieldsTable($fields);
$form[$datasource_id]['#title'] = $datasource->label();
}
$form['actions'] = $this->actionsElement($form, $form_state);
return $form;
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL)
{
$form_state->disableCache();
return $this->plugin->buildRedirectForm($form, $form_state, $order);
}
示例8: disableCache
/**
* {@inheritdoc}
*/
public function disableCache()
{
$this->decoratedFormState->disableCache();
return $this;
}
示例9: testDisableCache
/**
* @covers ::disableCache
*/
public function testDisableCache()
{
$this->decoratedFormState->disableCache()->shouldBeCalled();
$this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->disableCache());
}