Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function getForm(ViewEntityInterface $view, $display_id, $js)
 {
     $form_state = $this->getFormState($view, $display_id, $js);
     $view = $form_state->get('view');
     $key = $form_state->get('form_key');
     // @todo Remove the need for this.
     \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');
     // Reset the cache of IDs. Drupal rather aggressively prevents ID
     // duplication but this causes it to remember IDs that are no longer even
     // being used.
     Html::resetSeenIds();
     // check to see if this is the top form of the stack. If it is, pop
     // it off; if it isn't, the user clicked somewhere else and the stack is
     // now irrelevant.
     if (!empty($view->stack)) {
         $identifier = implode('-', array_filter([$key, $view->id(), $display_id, $form_state->get('type'), $form_state->get('id')]));
         // Retrieve the first form from the stack without changing the integer keys,
         // as they're being used for the "2 of 3" progress indicator.
         reset($view->stack);
         list($key, $top) = each($view->stack);
         unset($view->stack[$key]);
         if (array_shift($top) != $identifier) {
             $view->stack = array();
         }
     }
     // Automatically remove the form cache if it is set and the key does
     // not match. This way navigating away from the form without hitting
     // update will work.
     if (isset($view->form_cache) && $view->form_cache['key'] != $key) {
         unset($view->form_cache);
     }
     $form_class = get_class($form_state->getFormObject());
     $response = $this->ajaxFormWrapper($form_class, $form_state);
     // If the form has not been submitted, or was not set for rerendering, stop.
     if (!$form_state->isSubmitted() || $form_state->get('rerender')) {
         return $response;
     }
     // Sometimes we need to re-generate the form for multi-step type operations.
     if (!empty($view->stack)) {
         $stack = $view->stack;
         $top = array_shift($stack);
         // Build the new form state for the next form in the stack.
         $reflection = new \ReflectionClass($view::$forms[$top[1]]);
         /** @var $form_state \Drupal\Core\Form\FormStateInterface */
         $form_state = $reflection->newInstanceArgs(array_slice($top, 3, 2))->getFormState($view, $top[2], $form_state->get('ajax'));
         $form_class = get_class($form_state->getFormObject());
         $form_state->setUserInput(array());
         $form_url = views_ui_build_form_url($form_state);
         if (!$form_state->get('ajax')) {
             return new RedirectResponse($form_url->setAbsolute()->toString());
         }
         $form_state->set('url', $form_url);
         $response = $this->ajaxFormWrapper($form_class, $form_state);
     } elseif (!$form_state->get('ajax')) {
         // if nothing on the stack, non-js forms just go back to the main view editor.
         $display_id = $form_state->get('display_id');
         return new RedirectResponse($this->url('entity.view.edit_display_form', ['view' => $view->id(), 'display_id' => $display_id], ['absolute' => TRUE]));
     } else {
         $response = new AjaxResponse();
         $response->addCommand(new CloseModalDialogCommand());
         $response->addCommand(new Ajax\ShowButtonsCommand(!empty($view->changed)));
         $response->addCommand(new Ajax\TriggerPreviewCommand());
         if ($page_title = $form_state->get('page_title')) {
             $response->addCommand(new Ajax\ReplaceTitleCommand($page_title));
         }
     }
     // If this form was for view-wide changes, there's no need to regenerate
     // the display section of the form.
     if ($display_id !== '') {
         \Drupal::entityManager()->getFormObject('view', 'edit')->rebuildCurrentTab($view, $response, $display_id);
     }
     return $response;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $view_options = Views::getViewsAsOptions(TRUE, 'all', NULL, FALSE, TRUE);
     $form['views_field_view'] = ['#type' => 'details', '#title' => $this->t("View settings"), '#open' => TRUE];
     $form['view'] = ['#type' => 'select', '#title' => $this->t('View'), '#description' => $this->t('Select a view to embed.'), '#default_value' => $this->options['view'], '#options' => $view_options, '#ajax' => ['path' => views_ui_build_form_url($form_state)], '#submit' => [[$this, 'submitTemporaryForm']], '#executes_submit_callback' => TRUE, '#fieldset' => 'views_field_view'];
     // If there is no view set, use the first one for now.
     if (count($view_options) && empty($this->options['view'])) {
         $new_options = array_keys($view_options);
         $this->options['view'] = reset($new_options);
     }
     if ($this->options['view']) {
         $view = Views::getView($this->options['view']);
         $display_options = [];
         foreach ($view->storage->get('display') as $name => $display) {
             // Allow to embed a different display as the current one.
             if ($this->options['view'] != $this->view->storage->id() || $this->view->current_display != $name) {
                 $display_options[$name] = $display['display_title'];
             }
         }
         $form['display'] = ['#type' => 'select', '#title' => $this->t('Display'), '#description' => $this->t('Select a view display to use.'), '#default_value' => $this->options['display'], '#options' => $display_options, '#ajax' => ['path' => views_ui_build_form_url($form_state)], '#submit' => [[$this, 'submitTemporaryForm']], '#executes_submit_callback' => TRUE, '#fieldset' => 'views_field_view'];
         // Provide a way to directly access the views edit link of the child view.
         // Don't show this link if the current view is the selected child view.
         if (!empty($this->options['view']) && !empty($this->options['display']) && $this->view->storage->id() != $this->options['view']) {
             // use t() here, and set HTML on #link options.
             $link_text = $this->t('Edit "%view (@display)" view', ['%view' => $view_options[$this->options['view']], '@display' => $this->options['display']]);
             $form['view_edit'] = ['#type' => 'container', '#fieldset' => 'views_field_view'];
             $form['view_edit']['view_edit_link'] = ['#type' => 'link', '#title' => $link_text, '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $this->options['view'], 'display_id' => $this->options['display']], ['attributes' => ['target' => '_blank', 'class' => ['views-field-view-child-view-edit']], 'html' => TRUE]), '#attached' => ['library' => ['views_field_view/drupal.views_field_view']], '#prefix' => '<span>[</span>', '#suffix' => '<span>]</span>'];
             $form['view_edit']['description'] = ['#markup' => $this->t('Use this link to open the current child view\'s edit page in a new window.'), '#prefix' => '<div class="description">', '#suffix' => '</div>'];
         }
         $form['arguments'] = ['#title' => $this->t('Contextual filters'), '#description' => $this->t('Use a comma (,) or forwardslash (/) separated list of each contextual filter which should be forwared to the view.
       See below list of available replacement tokens. Static values are also be passed to child views if they do not match a token format.
       You could pass static ID\'s or taxonomy terms in this way. E.g. 123 or "my taxonomy term".'), '#type' => 'textfield', '#default_value' => $this->options['arguments'], '#fieldset' => 'views_field_view'];
         $form['available_tokens'] = ['#type' => 'details', '#title' => $this->t('Replacement patterns'), '#value' => $this->getTokenInfo(), '#fieldset' => 'views_field_view'];
     }
     $form['alter']['#access'] = FALSE;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $field = $this->getFieldDefinition();
     $formatters = $this->formatterPluginManager->getOptions($field->getType());
     $column_names = array_keys($field->getColumns());
     // If this is a multiple value field, add its options.
     if ($this->multiple) {
         $this->multiple_options_form($form, $form_state);
     }
     // No need to ask the user anything if the field has only one column.
     if (count($field->getColumns()) == 1) {
         $form['click_sort_column'] = array('#type' => 'value', '#value' => isset($column_names[0]) ? $column_names[0] : '');
     } else {
         $form['click_sort_column'] = array('#type' => 'select', '#title' => $this->t('Column used for click sorting'), '#options' => array_combine($column_names, $column_names), '#default_value' => $this->options['click_sort_column'], '#description' => $this->t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'));
     }
     $form['type'] = array('#type' => 'select', '#title' => $this->t('Formatter'), '#options' => $formatters, '#default_value' => $this->options['type'], '#ajax' => array('url' => views_ui_build_form_url($form_state)), '#submit' => array(array($this, 'submitTemporaryForm')), '#executes_submit_callback' => TRUE);
     $form['field_api_classes'] = array('#title' => $this->t('Use field template'), '#type' => 'checkbox', '#default_value' => $this->options['field_api_classes'], '#description' => $this->t('If checked, field api classes will be added by field templates. This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'), '#fieldset' => 'style_settings', '#weight' => 20);
     if ($this->multiple) {
         $form['field_api_classes']['#description'] .= ' ' . $this->t('Checking this option will cause the group Display Type and Separator values to be ignored.');
     }
     // Get the settings form.
     $settings_form = array('#value' => array());
     $format = isset($form_state->getUserInput()['options']['type']) ? $form_state->getUserInput()['options']['type'] : $this->options['type'];
     if ($formatter = $this->getFormatterInstance($format)) {
         $settings_form = $formatter->settingsForm($form, $form_state);
         // Convert field UI selector states to work in the Views field form.
         FormHelper::rewriteStatesSelector($settings_form, "fields[{$field->getName()}][settings_edit_form]", 'options');
     }
     $form['settings'] = $settings_form;
 }
 function options_form(&$form, &$form_state)
 {
     parent::options_form($form, $form_state);
     module_load_include('inc', 'views', 'modules/field/views_handler_field_field');
     $subfield = $this->field_info;
     $formatters = _field_view_formatter_options($subfield['type']);
     $column_names = array_keys($subfield['columns']);
     // If this is a multiple value field, add its options.
     if ($this->multiple) {
         $this->multiple_options_form($form, $form_state);
     }
     // No need to ask the user anything if the field has only one column.
     if (count($subfield['columns']) == 1) {
         $form['click_sort_column'] = array('#type' => 'value', '#value' => isset($column_names[0]) ? $column_names[0] : '');
     } else {
         $form['click_sort_column'] = array('#type' => 'select', '#title' => t('Column used for click sorting'), '#options' => drupal_map_assoc($column_names), '#default_value' => $this->options['click_sort_column'], '#description' => t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'), '#fieldset' => 'more');
     }
     $form['type'] = array('#type' => 'select', '#title' => t('Formatter'), '#options' => $formatters, '#default_value' => $this->options['type'], '#ajax' => array('path' => views_ui_build_form_url($form_state)), '#submit' => array('views_ui_config_item_form_submit_temporary'), '#executes_submit_callback' => TRUE);
     $form['field_api_classes'] = array('#title' => t('Use field template'), '#type' => 'checkbox', '#default_value' => $this->options['field_api_classes'], '#description' => t('If checked, field api classes will be added using field.tpl.php (or equivalent). This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'), '#fieldset' => 'style_settings', '#weight' => 20);
     if ($this->multiple) {
         $form['field_api_classes']['#description'] .= ' ' . t('Checking this option will cause the group Display Type and Separator values to be ignored.');
     }
     // Get the currently selected formatter.
     $format = $this->options['type'];
     $formatter = field_info_formatter_types($format);
     $settings = $this->options['settings'] + field_info_formatter_settings($format);
     // Provide an instance array for hook_field_formatter_settings_form().
     ctools_include('fields');
     $this->instance = ctools_fields_fake_field_instance($this->definition['subfield_name'], '_custom', $formatter, $settings);
     // Store the settings in a '_custom' view mode.
     $this->instance['display']['_custom'] = array('type' => $format, 'settings' => $settings);
     // Get the settings form.
     $settings_form = array('#value' => array());
     $function = $formatter['module'] . '_field_formatter_settings_form';
     if (function_exists($function)) {
         $settings_form = $function($subfield, $this->instance, '_custom', $form, $form_state);
     }
     $form['settings'] = $settings_form;
 }