Commit ad0276a4 authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #3001355 by jrockowitz: New access denied behaviors not working

parent 85a9177a
...@@ -157,9 +157,9 @@ class WebformEntitySettingsFormForm extends WebformEntitySettingsBaseForm { ...@@ -157,9 +157,9 @@ class WebformEntitySettingsFormForm extends WebformEntitySettingsBaseForm {
'#title' => $this->t('When a user is denied access to this webform'), '#title' => $this->t('When a user is denied access to this webform'),
'#options' => [ '#options' => [
WebformInterface::ACCESS_DENIED_DEFAULT => $this->t('Default (Displays the default access denied page)'), WebformInterface::ACCESS_DENIED_DEFAULT => $this->t('Default (Displays the default access denied page)'),
WebformInterface::ACCESS_DENIED_MESSAGE => $this->t('Inline (Displays message when access is denied to field and blocks)'), WebformInterface::ACCESS_DENIED_MESSAGE => $this->t('Inline (Displays message when access is denied to field, nodes, and blocks)'),
WebformInterface::ACCESS_DENIED_PAGE => $this->t('Page (Displays message when access is denied to forms, fields, and blocks)'), WebformInterface::ACCESS_DENIED_PAGE => $this->t('Page (Displays message when access is denied to forms, fields, nodes, and blocks)'),
WebformInterface::ACCESS_DENIED_LOGIN => $this->t('Login (Redirects to user login form and displays message)'), WebformInterface::ACCESS_DENIED_LOGIN => $this->t('Login (Redirects to user login form and displays message. Field, nodes, and block only display the message.)'),
], ],
'#required' => TRUE, '#required' => TRUE,
'#default_value' => $settings['form_access_denied'], '#default_value' => $settings['form_access_denied'],
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\webform\Plugin\Field\FieldFormatter; namespace Drupal\webform\Plugin\Field\FieldFormatter;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Serialization\Yaml; use Drupal\Core\Serialization\Yaml;
...@@ -138,20 +140,14 @@ class WebformEntityReferenceEntityFormatter extends WebformEntityReferenceFormat ...@@ -138,20 +140,14 @@ class WebformEntityReferenceEntityFormatter extends WebformEntityReferenceFormat
* {@inheritdoc} * {@inheritdoc}
*/ */
public function viewElements(FieldItemListInterface $items, $langcode) { public function viewElements(FieldItemListInterface $items, $langcode) {
// Get source entity.
$source_entity = $items->getEntity(); $source_entity = $items->getEntity();
$this->messageManager->setSourceEntity($source_entity);
// Determine if webform is previewed within a Paragraph on .edit_form. // Determine if webform is previewed within a Paragraph on .edit_form.
$is_paragraph_edit_preview = ($source_entity->getEntityTypeId() === 'paragraph' && preg_match('/\.edit_form$/', $this->routeMatch->getRouteName())) ? TRUE : FALSE; $is_paragraph_edit_preview = ($source_entity->getEntityTypeId() === 'paragraph' && preg_match('/\.edit_form$/', $this->routeMatch->getRouteName())) ? TRUE : FALSE;
$elements = []; $elements = [];
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) { foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
// Do not display the webform if the current user can't if ($is_paragraph_edit_preview) {
// create submissions.
if ($entity->id() && !$entity->access('submission_create')) {
$elements[$delta] = [];
}
elseif ($is_paragraph_edit_preview) {
// Webform can not be nested within node edit form because the nested // Webform can not be nested within node edit form because the nested
// <form> tags will cause unexpected validation issues. // <form> tags will cause unexpected validation issues.
$elements[$delta] = [ $elements[$delta] = [
...@@ -161,21 +157,28 @@ class WebformEntityReferenceEntityFormatter extends WebformEntityReferenceFormat ...@@ -161,21 +157,28 @@ class WebformEntityReferenceEntityFormatter extends WebformEntityReferenceFormat
]; ];
} }
else { else {
$values = []; $use_source_entity = $this->getSetting('source_entity');
if ($this->getSetting('source_entity')) { $elements[$delta] = [
$values += [ '#type' => 'webform',
'entity_type' => $source_entity->getEntityTypeId(), '#webform' => $entity,
'entity_id' => $source_entity->id(), '#default_data' => (!empty($items[$delta]->default_data)) ? Yaml::decode($items[$delta]->default_data) : [],
]; '#entity_type' => ($use_source_entity) ? $source_entity->getEntityTypeId() : NULL,
} '#entity_id' => ($use_source_entity) ? $source_entity->id() : NULL,
if (!empty($items[$delta]->default_data)) { ];
$values['data'] = Yaml::decode($items[$delta]->default_data);
}
$elements[$delta] = $entity->getSubmissionForm($values);
} }
$this->setCacheContext($elements[$delta], $entity, $items[$delta]); $this->setCacheContext($elements[$delta], $entity, $items[$delta]);
} }
return $elements; return $elements;
} }
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity) {
// Always allow access so that the Webform element can determine if the
// Webform is accessible or an access denied message should be displayed.
// @see \Drupal\webform\Element\Webform
return AccessResult::allowed();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment