X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdiff%2Fsrc%2FPlugin%2Fviews%2Ffield%2FDiffFrom.php;fp=web%2Fmodules%2Fcontrib%2Fdiff%2Fsrc%2FPlugin%2Fviews%2Ffield%2FDiffFrom.php;h=8af0ecc0b009cd821bf981152953d7e7a2476047;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/diff/src/Plugin/views/field/DiffFrom.php b/web/modules/contrib/diff/src/Plugin/views/field/DiffFrom.php new file mode 100644 index 000000000..8af0ecc0b --- /dev/null +++ b/web/modules/contrib/diff/src/Plugin/views/field/DiffFrom.php @@ -0,0 +1,97 @@ +t('Compare'); + parent::viewsForm($form, $form_state); + } + + /** + * Returns the diff_to field ID. + * + * @return string|null + * The diff_to field ID, or null if the field was not found on the view. + */ + protected function getToFieldId() { + foreach ($this->view->field as $id => $field) { + if ($field instanceof DiffTo) { + return $id; + } + } + } + + /** + * Submit handler for the bulk 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. + * + * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException + * Thrown when the user tried to access an action without access to it. + */ + public function viewsFormSubmit(array &$form, FormStateInterface $form_state) { + if ($form_state->get('step') == 'views_form_views_form') { + $diff_from = $form_state->getValue($this->options['id']); + $diff_from_entity = $this->loadEntityFromDiffFormKey($diff_from); + + $diff_to = $form_state->getValue($this->getToFieldId()); + $diff_to_entity = $this->loadEntityFromDiffFormKey($diff_to); + + $options = array( + 'query' => $this->getDestinationArray(), + ); + $entity_type_id = $diff_from_entity->getEntityTypeId(); + + $filter = \Drupal::service('plugin.manager.diff.layout')->getDefaultLayout(); + if ($diff_from_entity instanceof NodeInterface && $diff_to_entity instanceof NodeInterface) { + $form_state->setRedirect('diff.revisions_diff', [ + $entity_type_id => $diff_from_entity->id(), + 'left_revision' => $diff_from_entity->getRevisionId(), + 'right_revision' => $diff_to_entity->getRevisionId(), + 'filter' => $filter, + ], $options); + } + elseif ($diff_from_entity instanceof RevisionableInterface && $diff_to_entity instanceof RevisionableInterface) { + $route_name = 'entity.' . $entity_type_id . '.revisions_diff'; + $form_state->setRedirect($route_name, [ + $entity_type_id => $diff_from_entity->id(), + 'left_revision' => $diff_from_entity->getRevisionId(), + 'right_revision' => $diff_to_entity->getRevisionId(), + 'filter' => $filter, + ], $options); + } + } + } + +}