only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/src/Tests/ViewsFormMultipleTest.php @@ -0,0 +1,47 @@ +enableViewsTestModule(); + } + + /** + * Tests the a page with multiple View forms in it. + */ + public function testViewsFormMultiple() { + // Get the test page. + $this->drupalGet('views_test_form_multiple'); + + // Look for the first button of the second view form. + // @todo. + + // Submit the form for the button found. + // @todo. + + // Display the message returned by the button submission. + // @todo. + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_form_multiple.yml @@ -0,0 +1,130 @@ +langcode: en +status: true +dependencies: + module: + - node +id: test_form_multiple +label: '' +module: views +description: '' +tag: '' +base_table: views_test_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + display_title: Master + id: default + position: 0 + display_options: + access: + type: none + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + pager: + options: + id: 0 + items_per_page: 10 + offset: 0 + type: full + style: + type: table + options: + grouping: { } + row_class: '' + default_row_class: true + override: true + sticky: false + caption: '' + summary: '' + description: '' + columns: + id: id + field_form_button_test: field_form_button_test + info: + field_form_button_test: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + default: '-1' + empty_table: false + row: + type: fields + fields: + id: + field: id + id: id + relationship: none + table: views_test_data + plugin_id: numeric + field_form_button_test: + id: field_form_button_test + table: views + field: field_form_button_test + relationship: none + group_type: group + admin_label: '' + label: 'Field form button test' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + plugin_id: field_form_button_test + arguments: + 'null': + default_action: default + default_argument_type: fixed + field: 'null' + id: 'null' + must_not_be: false + table: views + plugin_id: 'null' only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/tests/modules/views_test_data/src/Controller/ViewsTestFormMultipleController.php @@ -0,0 +1,44 @@ + [ + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'view', + '#name' => 'test_form_multiple', + '#display_id' => 'default', + '#arguments' => ['arg1'], + '#embed' => TRUE, + ], + 'view_arg2' => [ + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'view', + '#name' => 'test_form_multiple', + '#display_id' => 'default', + '#arguments' => ['arg2'], + '#embed' => TRUE, + ], + ]; + return $build; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php @@ -0,0 +1,87 @@ +options['id'] . '--' . $row->index . '-->'; + } + + /** + * Form constructor for the views form. + * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + */ + public function viewsForm(&$form, FormStateInterface $form_state) { + // Make sure we do not accidentally cache this form. + $form['#cache']['max-age'] = 0; + // The view is empty, abort. + if (empty($this->view->result)) { + unset($form['actions']); + return; + } + + $form[$this->options['id']]['#tree'] = TRUE; + foreach ($this->view->result as $row_index => $row) { + $form[$this->options['id']][$row_index] = [ + '#type' => 'submit', + '#value' => t('Test Button'), + '#name' => 'test-button-' . $row_index, + '#test_button' => TRUE, + '#row_index' => $row_index, + '#attributes' => ['class' => ['test-button']], + ]; + } + } + + /** + * Submit handler for the views form. + * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + */ + public function viewsFormSubmit(&$form, FormStateInterface $form_state) { + $triggering_element = $form_state->getTriggeringElement(); + if (!empty($triggering_element['#test_button'])) { + $row_index = $triggering_element['#row_index']; + $view_args = !empty($this->view->args) ? implode(', ', $this->view->args) : $this->t('no arguments'); + drupal_set_message($this->t('The test button for @view_title (@display / @view_id) View with args: @args was submitted.', array('@view_title' => $this->view->getTitle(), '@display' => $this->view->current_display, '@view_id' => $this->view->id(), '@args' => $view_args))); + } + } + + /** + * {@inheritdoc} + */ + public function query() { + // Do nothing. + } + +} only in patch2: unchanged: --- a/core/modules/views/tests/modules/views_test_data/views_test_data.routing.yml +++ b/core/modules/views/tests/modules/views_test_data/views_test_data.routing.yml @@ -11,3 +11,11 @@ views_test_data.element_embed: _form: '\Drupal\views_test_data\Form\ViewsTestDataElementEmbedForm' requirements: _access: 'TRUE' + +views_test_data.form_multiple: + path: '/views_test_form_multiple' + defaults: + _title: 'Test Views Form Multiple' + _controller: '\Drupal\views_test_data\Controller\ViewsTestFormMultipleController::testPage' + requirements: + _access: 'TRUE'