Skip to content

Commit 3902e28

Browse files
committed
#1: WIP on Backdrop port
1 parent 27292be commit 3902e28

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

conditional_fields.module

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function conditional_fields_element_after_build($element, &$form_state) {
233233
return $element;
234234
}
235235

236-
$form = &$form_state['complete form'];
236+
$form = &$form_state['complete_form'];
237237

238238
// Avoid processing fields in fields_ui administration pages.
239239
if (backdrop_substr($form['#form_id'], 0, 9) == 'field_ui_') {
@@ -263,9 +263,11 @@ function conditional_fields_element_after_build($element, &$form_state) {
263263
}
264264

265265
// Attach dependent.
266-
if (isset($dependencies['dependents'][$field['#entity_type'] . '.' . $field['#bundle'] . '.' . $field['#field_name']])) {
267-
foreach ($dependencies['dependents'][$field['#entity_type']. '.' . $field['#bundle']. '.' . $field['#field_name']] as $id => $dependency) {
268-
$dependee_field_name = array_pop(explode('.',$dependency['dependee']));
266+
$field_instance_id = $form['#entity_type'] . '.' . $form['#bundle'] . '.' . $field['#field_name'];
267+
if (isset($dependencies['dependents'][$field_instance_id])) {
268+
foreach ($dependencies['dependents'][$field_instance_id] as $id => $dependency) {
269+
$dependency_parts = explode('.', $dependency['dependee']);
270+
$dependee_field_name = array_pop($dependency_parts);
269271
if (!isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
270272
conditional_fields_attach_dependency($form, array('#field_name' => $dependee_field_name), $field, $dependency['options'], $id);
271273
}
@@ -276,10 +278,10 @@ function conditional_fields_element_after_build($element, &$form_state) {
276278
// TODO: collect information about every element of the dependee widget, not
277279
// just the first encountered. This bottom-up approach would allow us to
278280
// define per-element sets of dependency values.
279-
//dpm($dependencies['dependees']);
280-
if (isset($dependencies['dependees'][$field['#entity_type']. '.' . $field['#bundle']. '.' . $field['#field_name']])) {
281-
foreach ($dependencies['dependees'][$field['#entity_type']. '.' . $field['#bundle']. '.' . $field['#field_name']] as $id => $dependency) {
282-
$dependent_field_name = array_pop(explode('.',$dependency['dependent']));
281+
if (isset($dependencies['dependees'][$field_instance_id])) {
282+
foreach ($dependencies['dependees'][$field_instance_id] as $id => $dependency) {
283+
$dependent_parts = explode('.', $dependency['dependent']);
284+
$dependent_field_name = array_pop($dependent_parts);
283285
if (!isset($form['#conditional_fields'][$field['#field_name']]['dependents'][$id])) {
284286
conditional_fields_attach_dependency($form, $field, array('#field_name' => $dependent_field_name), $dependency['options'], $id);
285287
}
@@ -361,7 +363,6 @@ function conditional_fields_element_after_build($element, &$form_state) {
361363
*/
362364
function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $options, $id = 0) {
363365
$options += conditional_fields_dependency_default_options();
364-
365366
// The absence of the $id parameter identifies a custom dependency.
366367
if (!$id) {
367368
// String values are accepted to simplify usage of this function with custom
@@ -426,7 +427,6 @@ function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $op
426427
*/
427428
function conditional_fields_form_after_build($form, &$form_state) {
428429
// Dependencies data is attached in conditional_fields_element_after_build().
429-
dpm('Why is this not firing?');
430430
if (empty($form['#conditional_fields'])) {
431431
return $form;
432432
}

0 commit comments

Comments
 (0)