Commit fc2a5fe0 authored by Jacob Rockowitz's avatar Jacob Rockowitz Committed by jrockowitz
Browse files

Issue #3169491 by jrockowitz: Use Element::isVisibleElement($element) instead...

Issue #3169491 by jrockowitz: Use Element::isVisibleElement($element) instead of $element['#access']
parent ec5fa932
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Theme hooks, preprocessor, and suggestions.
 */

use Drupal\Core\Render\Element;
use Drupal\file\Entity\File;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
@@ -576,7 +577,7 @@ function webform_preprocess_file_managed_file(&$variables) {
  }

  // Don't alter hidden file upload input.
  if (isset($element['upload']['#access']) && $element['upload']['#access'] === FALSE) {
  if (!Element::isVisibleElement($element['upload'])) {
    return;
  }

+2 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\webform_attachment\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\webform\Plugin\WebformElementManagerInterface;
use Drupal\webform\WebformInterface;
@@ -89,7 +90,7 @@ class WebformAttachmentController extends ControllerBase implements ContainerInj
    // Make sure element #access is not FALSE.
    // The #private property is used to to set #access to FALSE.
    // @see \Drupal\webform\Entity\Webform::initElementsRecursive
    if (isset($element['#access']) && $element['#access'] === FALSE) {
    if (!Element::isVisibleElement($element)) {
      throw new AccessDeniedHttpException();
    }

+2 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\webform_image_select\Element;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Url;
use Drupal\webform\Entity\WebformOptions as WebformOptionsEntity;
@@ -130,8 +131,7 @@ class WebformImageSelectElementImages extends FormElement {
      $value = $custom_value;
    }

    $has_access = (!isset($element['#access']) || $element['#access'] === TRUE);
    if ($element['#required'] && empty($value) && $has_access) {
    if (Element::isVisibleElement($element) && $element['#required'] && empty($value)) {
      WebformElementHelper::setRequiredError($element, $form_state);
    }

+2 −4
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Render\Markup;
use Drupal\webform\Element\WebformCompositeFormElementTrait;
@@ -222,9 +223,6 @@ class WebformOptionsCustom extends FormElement implements WebformOptionsCustomIn
  public static function validateWebformOptionsCustom(&$element, FormStateInterface $form_state, &$complete_form) {
    $value = NestedArray::getValue($form_state->getValues(), $element['select']['#parents']);

    // Determine if the element is visible. (#access !== FALSE)
    $has_access = (!isset($element['#access']) || $element['#access'] === TRUE);

    // Determine if the element has multiple values.
    $is_multiple = (empty($element['#multiple'])) ? FALSE : TRUE;

@@ -237,7 +235,7 @@ class WebformOptionsCustom extends FormElement implements WebformOptionsCustomIn
    }

    // Validate on elements with #access.
    if ($has_access && !empty($element['#required']) && $is_empty) {
    if (Element::isVisibleElement($element) && !empty($element['#required']) && $is_empty) {
      WebformElementHelper::setRequiredError($element, $form_state);
    }

+2 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\OptGroup;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Render\Element;
use Drupal\webform\Element\WebformAjaxElementTrait;
use Drupal\webform\Element\WebformEntityTrait;
use Drupal\webform\Element\WebformMessage;
@@ -532,7 +533,7 @@ class OptionsLimitWebformHandler extends WebformHandlerBase implements WebformOp
   */
  public static function validateElement(&$element, FormStateInterface $form_state, &$complete_form) {
    // Skip if element is not visible.
    if (isset($element['#access']) && $element['#access'] === FALSE) {
    if (!Element::isVisibleElement($element)) {
      return;
    }

Loading