Skip to content
Snippets Groups Projects

Find parent property path, if any.

Open Wim Leers requested to merge issue/drupal-3398982:3398982-parent-property-path into 11.x
Compare and
10 files
+ 616
68
Compare changes
  • Side-by-side
  • Inline
Files
10
@@ -97,11 +97,8 @@ public function loadDefaultValuesFromConfig(array $element): array {
@@ -97,11 +97,8 @@ public function loadDefaultValuesFromConfig(array $element): array {
$target = ConfigTarget::fromString($target);
$target = ConfigTarget::fromString($target);
}
}
$value = $this->configFactory()->getEditable($target->configName)->get($target->propertyPath);
$config = $this->configFactory()->getEditable($target->configName);
if ($target->fromConfig) {
$element['#default_value'] = $target->getValue($config);
$value = ($target->fromConfig)($value);
}
$element['#default_value'] = $value;
}
}
foreach (Element::children($element) as $key) {
foreach (Element::children($element) as $key) {
@@ -138,7 +135,9 @@ public function storeConfigKeyToFormElementMap(array $element, FormStateInterfac
@@ -138,7 +135,9 @@ public function storeConfigKeyToFormElementMap(array $element, FormStateInterfac
if (is_string($target)) {
if (is_string($target)) {
$target = ConfigTarget::fromString($target);
$target = ConfigTarget::fromString($target);
}
}
$map[$target->configName][$target->propertyPath] = $element['#array_parents'];
foreach ($target->propertyPaths as $property_path) {
 
$map[$target->configName][$property_path] = $element['#array_parents'];
 
}
$form_state->set(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP, $map);
$form_state->set(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP, $map);
}
}
foreach (Element::children($element) as $key) {
foreach (Element::children($element) as $key) {
@@ -173,10 +172,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
@@ -173,10 +172,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
$property_path = $violation->getPropertyPath();
$property_path = $violation->getPropertyPath();
// Default to index 0.
// Default to index 0.
$index = 0;
$index = 0;
// Detect if this is a sequence property path, and if so, determine the
// actual sequence index.
// Detect if this is a sequence item property path, and if so, attempt
$matches = [];
// to fall back to the containing sequence's property path.
if (preg_match("/.*\.(\d+)$/", $property_path, $matches) === 1) {
if (!isset($map[$config_name][$property_path]) && preg_match("/.*\.(\d+)$/", $property_path, $matches) === 1) {
$index = intval($matches[1]);
$index = intval($matches[1]);
// The property path as known in the config key-to-form element map
// The property path as known in the config key-to-form element map
// will not have the sequence index in it.
// will not have the sequence index in it.
@@ -192,7+191,7 @@
@@ -192,7+191,7 @@
// is the entire form.
// is the entire form.
$form_element_name = '';
$form_element_name = '';
}
}
$violations_per_form_element[$form_element_name][$index] = $violation;
$violations_per_form_element[$form_element_name][$index] = $violation;
}
}
// Now that we know how many constraint violation messages exist per form
// Now that we know how many constraint violation messages exist per form
@@ -282,7+281,7 @@
@@ -282,7+281,7 @@
foreach ($map[$config->getName()] as $array_parents) {
foreach ($map[$config->getName()] as $array_parents) {
$target = ConfigTarget::fromForm($array_parents, $form);
$target = ConfigTarget::fromForm($array_parents, $form);
if ($target->configName === $config->getName()) {
if ($target->configName !== $config->getName()) {
$value = $form_state->getValue($target->elementParents);
continue;
if ($target->toConfig) {
$value = ($target->toConfig)($value);
}
$config->set($target->propertyPath, $value);
}
}
 
$value = $form_state->getValue($target->elementParents);
 
$target->setValue($config, $value, $form_state);
}
}
}
}
Loading