FOF30\Form\Form::findHeader PHP Метод

findHeader() защищенный Метод

Method to get a header field represented as an XML element object.
С версии: 2.0
protected findHeader ( string $name, string $group = null ) : mixed
$name string The name of the form field.
$group string The optional dot-separated form group path on which to find the field.
Результат mixed The XML element object for the field or boolean false on error.
    protected function findHeader($name, $group = null)
    {
        $element = false;
        $fields = array();
        // Make sure there is a valid JForm XML document.
        if (!$this->xml instanceof \SimpleXMLElement) {
            return false;
        }
        // Let's get the appropriate field element based on the method arguments.
        if ($group) {
            // Get the fields elements for a given group.
            $elements =& $this->findGroup($group);
            // Get all of the field elements with the correct name for the fields elements.
            /** @var \SimpleXMLElement $element */
            foreach ($elements as $element) {
                // If there are matching field elements add them to the fields array.
                if ($tmp = $element->xpath('descendant::header[@name="' . $name . '"]')) {
                    $fields = array_merge($fields, $tmp);
                }
            }
            // Make sure something was found.
            if (!$fields) {
                return false;
            }
            // Use the first correct match in the given group.
            $groupNames = explode('.', $group);
            /** @var \SimpleXMLElement $field */
            foreach ($fields as &$field) {
                // Get the group names as strings for ancestor fields elements.
                $attrs = $field->xpath('ancestor::headerfields[@name]/@name');
                $names = array_map('strval', $attrs ? $attrs : array());
                // If the field is in the exact group use it and break out of the loop.
                if ($names == (array) $groupNames) {
                    $element =& $field;
                    break;
                }
            }
        } else {
            // Get an array of fields with the correct name.
            $fields = $this->xml->xpath('//header[@name="' . $name . '"]');
            // Make sure something was found.
            if (!$fields) {
                return false;
            }
            // Search through the fields for the right one.
            foreach ($fields as &$field) {
                // If we find an ancestor fields element with a group name then it isn't what we want.
                if ($field->xpath('ancestor::headerfields[@name]')) {
                    continue;
                } else {
                    $element =& $field;
                    break;
                }
            }
        }
        return $element;
    }