Skip to content

Commit

Permalink
Merge pull request #32 from ContaoBayern/feature-ignore-fields
Browse files Browse the repository at this point in the history
Feature "ignore fields which are mandatory by default"
  • Loading branch information
Jörg Moldenhauer authored Jan 21, 2018
2 parents 0e5dfa8 + ba55dbf commit 4c7c482
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
### New
* Usage of JavaScript and visibility toggling can be controlled via backend option (see #25)

### Changed
* Fields which are mandatory by default are not handled by our extension anymore (see #28)


## 1.0.1

Expand Down
29 changes: 27 additions & 2 deletions classes/FieldDependencyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,37 @@ private function initializeDependencies()
}

// Only handle fields which are actually used by the frontend module
// and are not mandatory by default
$dependents = [
'mandatory' => array_intersect($dependents['mandatory'], $this->editable),
'visibility' => array_intersect($dependents['visibility'], $this->editable)
'mandatory' => $this->filterDependents($dependents['mandatory']),
'visibility' => $this->filterDependents($dependents['visibility']),
];

// Skip fields with empty dependents
if (empty($dependents['mandatory']) || empty($dependents['visibility'])) {
continue;
}

$this->dependencies[$field] = $dependents;
}
}

/**
* Removes fields which are not used by the frontend module
* or are mandatory by default.
*
* @param array $fields The fields to filter
*
* @return array An array containing only fields which are used by
* the frontend module and are not mandatory by default
*/
private function filterDependents($fields)
{
$fields = array_intersect($fields, $this->editable);
$fields = array_filter($fields, function ($field) {
return !$GLOBALS['TL_DCA']['tl_member']['fields'][$field]['eval']['mandatory'];
});

return $fields;
}
}

0 comments on commit 4c7c482

Please sign in to comment.