Commit 46dc482b authored by Jordan Karlov's avatar Jordan Karlov Committed by Jordan Karlov
Browse files

Issue #3261306 by JordiK: Rate widget view path (in embedded view) is not set...

Issue #3261306 by JordiK: Rate widget view path (in embedded view) is not set correctly after second ajax request
parent e165eb3d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\votingapi\Entity\Vote;
@@ -152,6 +153,8 @@ class RateWidgetBaseForm extends ContentEntityForm {
    $template = $settings->get('template');
    $rate_widget = $form_state->get('rate_widget');
    $value_type = $entity->get('value_type')->value;
    $is_views_field = $form_state->get('is_views_field');
    $views_url = $form_state->get('views_url');

    $form['#cache']['contexts'][] = 'user.permissions';
    $form['#cache']['contexts'][] = 'user.roles:authenticated';
@@ -359,6 +362,14 @@ class RateWidgetBaseForm extends ContentEntityForm {
      ],
    ];

    // Set the url of the ajax call if the rate form is in a view.
    if ($is_views_field == TRUE) {
      $form['submit']['#ajax']['url'] = $views_url;
      $form['submit']['#ajax']['options'] = [
        'query' => \Drupal::request()->query->all() + [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE],
      ];
    }

    // Base widget template. Can create additional twig templates.
    $form['#theme'] = 'rate_widget';
    $form['#rate_widget'] = $rate_widget;
+13 −4
Original line number Diff line number Diff line
@@ -170,6 +170,14 @@ class RateWidgetBase extends PluginBase {
      $option_classes[$option['value']] = isset($option['class']) ? $option['class'] : '';
    }

    // Add information if the form is built in a view.
    $is_views_field = FALSE;
    $views_url = FALSE;
    if ($settings->get('isViewsField') == TRUE) {
      $is_views_field = TRUE;
      $views_url = $settings->get('viewsUrl');
    }

    /*
     * @TODO: remove custom entity_form_builder once
     *   https://www.drupal.org/node/766146 is fixed.
@@ -181,13 +189,16 @@ class RateWidgetBase extends PluginBase {
      'classes' => $option_classes,
      'show_own_vote' => '1',
      'readonly' => FALSE,
      // @TODO: remove following keys when #766146 fixed (multiple form_ids).
      'is_views_field' => $is_views_field,
      'views_url' => $views_url,
      // @todo Remove following keys when #766146 is fixed (multiple form_ids).
      'entity_type' => $entity_type,
      'entity_bundle' => $entity_bundle,
      'entity_id' => $entity_id,
      'vote_type' => $vote_type,
      'rate_widget' => $rate_widget,
    ]);

    return $form;
  }

@@ -340,9 +351,7 @@ class RateWidgetBase extends PluginBase {

    $window = $window_field_setting;
    if ($use_site_default) {
      /*
       * @var \Drupal\Core\Config\ImmutableConfig $voting_configuration
       */
      /** @var \Drupal\Core\Config\ImmutableConfig $voting_configuration */
      $voting_configuration = $this->configFactory->get('votingapi.settings');
      $window = $voting_configuration->get($window_type);
    }
+4 −0
Original line number Diff line number Diff line
@@ -241,6 +241,10 @@ class RateWidgetField extends FieldPluginBase {
      // Currently using only two vote types - change, if more needed/used.
      $vote_type = ($widget_template == 'fivestar') ? $widget_template : 'updown';

      // Mark the widget being part of a view and add the view url.
      $widget->set('isViewsField', FALSE);
      $widget->set('viewsUrl', $this->view->getUrl());

      // Get the rate widget rating form.
      $form = $rate_widget_base_service->getForm($entity_type_id, $bundle, $entity_id, $vote_type, $value_type, $widget_name, $widget);
      $form = ($widget_display === 'summary') ? $form['#results'] : $form;