Back to FormHelper class

Method addPrefix

protected static array
addPrefix
(mixed $entity, mixed $new = null)
Method to add a namespace to the list of namespaces for one of the form's entities.
Parameters
  • string $entity Form's entity name for which paths will be added.
  • mixed $new A namespace or array of namespaces to add.
Returns
  • array The list of namespaces that have been added.
Since
  • 3.8.0
Class: FormHelper
Project: Joomla

Method addPrefix - Source code

/**
 * Method to add a namespace to the list of namespaces for one of the form's entities.
 * Currently supported entities: field, rule and form. You are free to support your own in a subclass.
 *
 * @param   string  $entity  Form's entity name for which paths will be added.
 * @param   mixed   $new     A namespace or array of namespaces to add.
 *
 * @return  array  The list of namespaces that have been added.
 *
 * @since   3.8.0
 */
protected static function addPrefix($entity, $new = null)
{
    // Reference to an array with namespaces for current entity
    $prefixes =& self::$prefixes[$entity];
    // Add the default entity's search namespace if not set.
    if (empty($prefixes)) {
        $prefixes[] = __NAMESPACE__ . '\\' . ucfirst($entity);
    }
    // Force the new namespace(s) to an array.
    settype($new, 'array');
    // Add the new paths to the stack if not already there.
    foreach ($new as $prefix) {
        $prefix = trim($prefix);
        if (\in_array($prefix, $prefixes)) {
            continue;
        }
        array_unshift($prefixes, $prefix);
    }
    return $prefixes;
}