Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign element uid to relationship between parent and child #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brunoviana
Copy link

Today it's impossible to retrieve and specific child block from a parent using its _uid because there's not an alias linking the child to the parent, so code like below will return anything.

<?php 
$buttonElement = $parent->getButton();

if ($buttonElement):
?>
    <div>
        <?= $parent->getChildHtml($buttonElement[0]['_uid']) ?>
    </div>
<?php endif; ?>

The reason for this is due to the method getChildHtml that calls \Magento\Framework\Data\Structure::getChildId method to retrieve the child block. Below a snippet of this method.

public function getChildId($parentId, $alias)
{
    if (isset($this->_elements[$parentId][self::CHILDREN])) {
        return array_search($alias, $this->_elements[$parentId][self::CHILDREN]);
    }
    return false;
}

This method uses `$alias' to retrieve the child block.

To make it possible the method \Magento\Framework\View\Element\AbstractBlock::append receives a second parameter with this alias and this PR uses this to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant