GrafikMatthew GrafikMatthew - 1 year ago 81
PHP Question

Pimcore: Retrieving Documents or Pages from Editable Links

I am trying to retrieve the Document Object or Page Object from an editable link in Pimcore. As per the documentation, I have access to the following methods:

  • getHref()
    Get the path of this link as

  • getText()
    Get the text of the link as

  • getTarget()
    Get the target of the link as

  • getParameters()
    Get the query params of the link as

  • getAnchor()
    Get the anchor text of the link as

  • getTitle()
    Get the title of the link as

  • getRel()
    Get the rel text of the link as

  • getTabindex()
    Get the tabindex of the link as

  • getAccessKey()
    Get the access key of the link as

  • isEmpty()
    Whether the editable is empty or not


<?php if( !empty( $this->block( "topfive_linkblock" ) ) ) : ?>
<ul class="wrapper">
<?php while( $this->block( "topfive_linkblock" )->loop() ) : ?>
<li><?= $this->link( "topfive_links" ); ?></li>
<?php endwhile; ?>
<?php endif; ?>

While this does well to create anchor links, I'd like to be able to get the Custom Properties for these pages so I can pull things over like preview images and other bits of information.

With WordPress, you can get posts by their URL, though I could not find a similar function in Pimcore/Zend.

Additional Info

If I use the undocumented method
I can get an Array with what I need, but I don't want to access the key as an array if that's no the appropriate way to do this (in case architecture changes alter the behavior in the future or remove this method).

<?= print_r( $this->link( "topfive_links" )->getDataForResource(), true ); ?>


[text] => Associations
[path] => /customers/associations
[target] =>
[parameters] =>
[anchor] =>
[title] =>
[accesskey] =>
[rel] =>
[tabindex] =>
[class] =>
[attributes] =>
[internal] => 1
[internalId] => 49
[internalType] => document
[type] => internal

The number in the
key is what I'm aiming for. My question is, what's the appropriate and most efficient way this can be done? Can I simply access this value from this array safely?

Accepted Solution:

Igor's solution works in both respects. We ended up using the HREF editable instead of the LINK editable.

Answer Source

You can get all the data about the element in link editable this way:

/** @var \Pimcore\Model\Document\Tag\Link $link */
$link = $this->link( "topfive_links" );

<?php if ($this->editmode): ?>

    <?php if( !empty( $this->block( "topfive_linkblock" ) ) ) : ?>
        <ul class="wrapper">
            <?php while( $this->block( "topfive_linkblock" )->loop() ) : ?>
                <li><?= $link ?></li>
            <?php endwhile; ?>
    <?php endif; ?>

<?php else: ?>

    while( $this->block( "topfive_linkblock" )->loop() ) {
        $link = $this->link( "topfive_links" );
        $linkElementData = $link->getData();

        $element = null;
        if ($linkElementData["internal"]) {
            $elementId = $linkElementData["internalId"];
            switch ($linkElementData["internalType"]) {
                case "document":
                    $element = \Pimcore\Model\Document::getById($elementId);

                case "asset":
                    $element = \Pimcore\Model\Asset::getById($elementId);

        if ($element) {
            echo get_class($element) . "<br>";

<?php endif ?>

For your use case the href editable might be a better choice:

With href editable you can just use getElement method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download