/**
* Method to synchronize any field, form or rule paths contained in the XML document.
*
* @return boolean True on success.
*
* @since 1.7.0
* @todo Maybe we should receive all addXXXpaths attributes at once?
*/
protected function syncPaths()
{
// Make sure there is a valid Form XML document.
if (!$this->xml instanceof \SimpleXMLElement) {
throw new \UnexpectedValueException(sprintf('%s::%s `xml` is not an instance of SimpleXMLElement', \get_class($this), __METHOD__));
}
// Get any addfieldpath attributes from the form definition.
$paths = $this->xml->xpath('//*[@addfieldpath]/@addfieldpath');
$paths = array_map('strval', $paths ?: []);
// Add the field paths.
foreach ($paths as $path) {
$path = JPATH_ROOT . '/' . ltrim($path, '/\\');
self::addFieldPath($path);
}
// Get any addformpath attributes from the form definition.
$paths = $this->xml->xpath('//*[@addformpath]/@addformpath');
$paths = array_map('strval', $paths ?: []);
// Add the form paths.
foreach ($paths as $path) {
$path = JPATH_ROOT . '/' . ltrim($path, '/\\');
self::addFormPath($path);
}
// Get any addrulepath attributes from the form definition.
$paths = $this->xml->xpath('//*[@addrulepath]/@addrulepath');
$paths = array_map('strval', $paths ?: []);
// Add the rule paths.
foreach ($paths as $path) {
$path = JPATH_ROOT . '/' . ltrim($path, '/\\');
self::addRulePath($path);
}
// Get any addrulepath attributes from the form definition.
$paths = $this->xml->xpath('//*[@addfilterpath]/@addfilterpath');
$paths = array_map('strval', $paths ?: []);
// Add the rule paths.
foreach ($paths as $path) {
$path = JPATH_ROOT . '/' . ltrim($path, '/\\');
self::addFilterPath($path);
}
// Get any addfieldprefix attributes from the form definition.
$prefixes = $this->xml->xpath('//*[@addfieldprefix]/@addfieldprefix');
$prefixes = array_map('strval', $prefixes ?: []);
// Add the field prefixes.
foreach ($prefixes as $prefix) {
FormHelper::addFieldPrefix($prefix);
}
// Get any addformprefix attributes from the form definition.
$prefixes = $this->xml->xpath('//*[@addformprefix]/@addformprefix');
$prefixes = array_map('strval', $prefixes ?: []);
// Add the field prefixes.
foreach ($prefixes as $prefix) {
FormHelper::addFormPrefix($prefix);
}
// Get any addruleprefix attributes from the form definition.
$prefixes = $this->xml->xpath('//*[@addruleprefix]/@addruleprefix');
$prefixes = array_map('strval', $prefixes ?: []);
// Add the field prefixes.
foreach ($prefixes as $prefix) {
FormHelper::addRulePrefix($prefix);
}
// Get any addruleprefix attributes from the form definition.
$prefixes = $this->xml->xpath('//*[@addfilterprefix]/@addfilterprefix');
$prefixes = array_map('strval', $prefixes ?: []);
// Add the field prefixes.
foreach ($prefixes as $prefix) {
FormHelper::addFilterPrefix($prefix);
}
return true;
}