Commit 1f84fd58 authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #2999765 by jrockowitz, jastraat: Notice: Uninitialized string offset: 0...

Issue #2999765 by jrockowitz, jastraat: Notice: Uninitialized string offset: 0 in Drupal\Core\Render\Element::property()
parent c5d44b46
......@@ -10,7 +10,6 @@ use Drupal\Core\Serialization\Yaml;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\user\Entity\User;
......@@ -1224,7 +1223,7 @@ class Webform extends ConfigEntityBundleBase implements WebformInterface {
$elements = WebformElementHelper::removeIgnoredProperties($elements);
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......@@ -1424,7 +1423,7 @@ class Webform extends ConfigEntityBundleBase implements WebformInterface {
*/
protected function setElementPropertiesRecursive(array &$elements, $key, array $properties, $parent_key = '') {
foreach ($elements as $element_key => &$element) {
if (Element::property($element_key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $element_key)) {
continue;
}
......@@ -1476,7 +1475,7 @@ class Webform extends ConfigEntityBundleBase implements WebformInterface {
*/
protected function deleteElementRecursive(array &$elements, $key) {
foreach ($elements as $element_key => &$element) {
if (Element::property($element_key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $element_key)) {
continue;
}
......@@ -1505,7 +1504,7 @@ class Webform extends ConfigEntityBundleBase implements WebformInterface {
*/
protected function collectSubElementKeysRecursive(array &$sub_element_keys, array $elements) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
$sub_element_keys[$key] = $key;
......
......@@ -4,7 +4,7 @@ namespace Drupal\webform\EntitySettings;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\webform\Utility\WebformElementHelper;
/**
* Base webform entity settings form.
......@@ -62,8 +62,7 @@ abstract class WebformEntitySettingsBaseForm extends EntityForm {
*/
protected function appendDefaultValueToElementDescriptions(array &$form, array $default_settings) {
foreach ($form as $key => &$element) {
// Skip if not a FAPI element.
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......
......@@ -8,7 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Render\Element;
use Drupal\webform\Utility\WebformElementHelper;
use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionConditionsValidatorInterface;
use Drupal\webform\WebformSubmissionInterface;
......@@ -611,7 +611,7 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn
$default_configuration = $this->defaultConfiguration();
foreach ($elements as $element_key => &$element) {
// Only a form element can have #parents.
if (Element::property($element_key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $element_key)) {
continue;
}
......
......@@ -71,6 +71,19 @@ class WebformElementHelper {
*/
protected static $ignoredSubPropertiesRegExp;
/**
* Determine if an element and its key is a renderable array.
*
* @param array|mixed $element
* An element.
*
* @return bool
* TRUE if an element and its key is a renderable array.
*/
public static function isElement($element, $key) {
return (Element::child($key) && is_array($element));
}
/**
* Determine if an element is a webform element and should be enhanced.
*
......@@ -400,7 +413,7 @@ class WebformElementHelper {
public static function getFlattened(array $elements) {
$flattened_elements = [];
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......
......@@ -191,7 +191,7 @@ class WebformFormHelper {
*/
protected static function flattenElementsRecursive(array &$build, array &$elements, array &$duplicate_element_keys) {
foreach ($build as $key => &$element) {
if (Element::child($key) && is_array($element)) {
if (WebformElementHelper::isElement($element, $key)) {
// If there are duplicate element keys create an array of referenced
// elements.
if (isset($elements[$key])) {
......
......@@ -247,7 +247,7 @@ class WebformEntityElementsValidator implements WebformEntityElementsValidatorIn
*/
protected function getDuplicateNamesRecursive(array $elements, array &$names) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
if (isset($element['#type'])) {
......@@ -355,7 +355,7 @@ class WebformEntityElementsValidator implements WebformEntityElementsValidatorIn
*/
protected function getElementKeysRecursive(array $elements, array &$names) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
if (isset($element['#type'])) {
......
......@@ -3,7 +3,6 @@
namespace Drupal\webform;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\webform\Plugin\WebformElement\WebformElement;
use Drupal\webform\Plugin\WebformElementManagerInterface;
......@@ -164,7 +163,7 @@ class WebformSubmissionConditionsValidator implements WebformSubmissionCondition
*/
protected function validateFormRecursive(array $form, FormStateInterface $form_state) {
foreach ($form as $key => $element) {
if (!Element::child($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......@@ -262,7 +261,7 @@ class WebformSubmissionConditionsValidator implements WebformSubmissionCondition
*/
protected function submitFormRecursive(array $elements, WebformSubmissionInterface $webform_submission, array &$data, $visible = TRUE) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......@@ -597,7 +596,7 @@ class WebformSubmissionConditionsValidator implements WebformSubmissionCondition
*/
protected function getBuildElementsRecusive(array &$elements, array &$form, array $parent_states = []) {
foreach ($form as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......
......@@ -24,6 +24,7 @@ use Drupal\webform\Plugin\WebformElement\Hidden;
use Drupal\webform\Plugin\WebformElementManagerInterface;
use Drupal\webform\Plugin\WebformHandlerInterface;
use Drupal\webform\Utility\WebformArrayHelper;
use Drupal\webform\Utility\WebformElementHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -1957,7 +1958,7 @@ class WebformSubmissionForm extends ContentEntityForm {
*/
protected function hideElements(array &$elements) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......@@ -1980,7 +1981,7 @@ class WebformSubmissionForm extends ContentEntityForm {
*/
protected function prepareElements(array &$elements, array &$form, FormStateInterface $form_state) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......@@ -2022,7 +2023,7 @@ class WebformSubmissionForm extends ContentEntityForm {
*/
protected function populateElements(array &$elements, array $values) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......
......@@ -7,8 +7,8 @@ use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Render\Element;
use Drupal\webform\Plugin\WebformElementManagerInterface;
use Drupal\webform\Utility\WebformElementHelper;
use Drupal\webform\Utility\WebformYaml;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -146,8 +146,7 @@ class WebformSubmissionViewBuilder extends EntityViewBuilder implements WebformS
$build = [];
foreach ($elements as $key => $element) {
// Make sure this is an element.
if (!is_array($element) || Element::property($key)) {
if (!WebformElementHelper::isElement($element, $key)) {
continue;
}
......
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