Back to RouterViewConfiguration class

Method setParent

public \Joomla\CMS\Component\Router\RouterViewConfiguration
setParent
(\Joomla\CMS\Component\Router\RouterViewConfiguration $parent, mixed $parentKey = null)
Set the parent view of this view
Parameters
  • \Joomla\CMS\Component\Router\RouterViewConfiguration $parent Parent view object
  • string $parentKey Key of the parent view in this context
Returns
  • \Joomla\CMS\Component\Router\RouterViewConfiguration This object for chaining
Since
  • 3.5

Method setParent - Source code

/**
 * Set the parent view of this view
 *
 * @param   RouterViewConfiguration  $parent     Parent view object
 * @param   string                   $parentKey  Key of the parent view in this context
 *
 * @return  RouterViewConfiguration  This object for chaining
 *
 * @since   3.5
 */
public function setParent(RouterViewConfiguration $parent, $parentKey = null)
{
    if ($this->parent) {
        $key = array_search($this, $this->parent->children);
        if ($key !== false) {
            unset($this->parent->children[$key]);
        }
        if ($this->parent_key) {
            $child_key = array_search($this->parent_key, $this->parent->child_keys);
            unset($this->parent->child_keys[$child_key]);
        }
    }
    $this->parent = $parent;
    $parent->children[] = $this;
    $this->path = $parent->path;
    $this->path[] = $this->name;
    $this->parent_key = $parentKey ?? false;
    if ($parentKey) {
        $parent->child_keys[] = $parentKey;
    }
    return $this;
}