Icon link in list to custom php script

Status
Not open for further replies.

achartier

Super Moderator
Staff member
I am wondering how best to do this. I played with a few things including the user_ajax call but before I get too far in I thought I would ask the community.

I have a list and one element is a db join to another table. When this element is displayed in the list view I display it as an icon. What I want to happen is when a user clicks this icon a php script to run. In this php script I will pull data from a number of tables and create a pdf file which I then wish to output to the user.

I would like to be able to access J! functions and fabrik models inside this script if possible.

I can get a link on the icon using the list view settings of the element but I have run into framework access issues if I simply run a custom php file, and when I tried a user_ajax call but am not sure this is really the best way to handle it.

Open to ideas, thanks.
 
I have some of those but I want the link to be attached to the icon rather than as a separate button at the end of the list row, and I don't really want a multiple button at the top.
 
When you choose to use a tool like Fabrik to save you writing everything by hand, one of the compromises you accept is that sometimes there is no easy way to achieve exactly what you want and you need to compromise.
 
Fair enough. Question though, if I select link to details and choose a custom link, I get a link on the element value. As soon as I change to display as icon I get no link. Should I not still get a link?

I see in the html that two anchor entities are created in the same cell for the element. The first anchor contains the link defined as a custom link, the second anchor contains the icon. Since the first anchor does not contain any text there is nothing to click on. I would think if you are allowing a link to details (or a custom ink) that these should be active on the icon as well.
 
I think the element with list view icon is displayed via \components\com_fabrik\layouts\element\fabrik-element-listicon-tip.php
You can override this layout.
 
May be a bug. Compare the code and in particular use of onClick="return false;" which probably cancels the effect of clicking on the icon (and also different use of $d->target):

fabrik-element-listicon-tip.php
Code:
<a
        class="fabrikTip"
          onclick="return false"
        <?php echo $d->target; ?>
        href="<?php echo $d->href; ?>"
        opts='<?php echo $d->opts; ?>'
        title="<?php echo $d->title; ?>"
        data-trigger="hover"
>
    <?php echo $d->img; ?>
</a>
fabrik-element-custom-link.php
Code:
<a data-loadmethod="<?php echo $d->loadMethod;?>"
    class="<?php echo $d->class; ?>"
    data-list="<?php echo $d->dataList; ?>"
    data-isajax="<?php echo $d->isAjax; ?>"
    data-rowid="<?php echo $d->rowId; ?>"
    data-iscustom="<?php if ($d->isCustom) echo '1'; else echo '0'; ?>"
    href="<?php echo $d->link; ?>"
    <?php if ($d->target !== '') : ?>
        target="<?php echo $d->target; ?>"
    <?php endif; ?>
>
<?php echo $d->data; ?>
</a>

So I would recommend editing the fabrik-element-listicon-tip.php file and removing onclick="return false" and see if that helps. If it does please submit a PR to fix this permanently.
 
Will do. I solved my script access issue, came to me in my dreams. Jumi will do all that I need.
 
Now that I have dug into this further I think I understand the problem. When icons are required elementlist.php (lines 644-658) replaces the display text with an attribute tag for the image. An example of this is:
Code:
<a class="fabrikTip" onclick="return false" href="#" opts="{&quot;position&quot;:&quot;top&quot;}" title="" data-trigger="hover" data-original-title="<span>Alexandrea Boutilier</span>">
    <img src="https://localhost/media/com_fabrik/images/heart30.png" class="fabrikImg">
</a>
elementlist.php then calls the _addLink function (line 668) in list.php. _addLink assumes this link is just display data (usually the element value) and passes it as such to the $layout->render function.

I haven't looked very close at the render function but it seems that it recognizes the image data as another full tag and renders it separately after the element link. The result is 2 anchors in the one cell as shown here:
Code:
<td class="client_data___Par_Q fabrik_element fabrik_list_16_group_45">
            <a data-loadmethod="xhr" class="fabrik___rowlink  fabrik_edit" data-list="list_16_com_fabrik_16" data-isajax="0" data-rowid="842" data-iscustom="1" href="/custom_scripts/fabrik/parq.php" target="_blank">
</a><a class="fabrikTip" onclick="return false" href="#" opts="{&quot;position&quot;:&quot;top&quot;}" title="" data-trigger="hover" data-original-title="<span>Alexandrea Boutilier</span>">
    <img src="https://localhost/media/com_fabrik/images/heart30.png" class="fabrikImg">
</a>
        </td>
The upshot of this is that the image overlays in the cell and the underlying link in the first <a> can never be clicked.

The answer is to create a combined anchor like this:
Code:
<a data-loadmethod="xhr" class="fabrik___rowlink  fabrik_edit fabrikTip" data-list="list_16_com_fabrik_16" data-isajax="0" data-rowid="842" data-iscustom="1" href="/custom_scripts/fabrik/parq.php" target="_blank" opts="{"position":"top"}" title="" data-trigger="hover" data-original-title="<span>Alexandrea Boutilier</span>"><img src="https://localhost/media/com_fabrik/images/heart30.png" class="fabrikImg">
</a>
This works to show the icon, the tooltip, and the custom link is active on the icon.

Now, the logic in elementlist.php and list.php is pretty well integrated with using the 2 separate layouts. I am unsure what the best way would be to fix this up. We could have a third layout fabrik-element-custom-icon-link or similar name and render that when we have a custom link and an icon. But before I go down that road it is probably best if Hugh take a quick look and see if I am on the right track and perhaps he has a better solution he can suggest.
 
You mean a separate layout? If so I will see if I can work it up and integrate and do a pr for it.
 
Does this still require the other change you made? Can't seem to find it now, but removing that replaceWithicon() call.

-- hugh
 
Sophist and I bantered the other one around and decided it was best left alone for backward compatibility. If one understand the relationships between the otpions it is easy to set them to your desired requirement.
 
Hugh, have you had a chance to test the pr? Any chance you can merge it? I cannot update from git until this is done (or I have to keep manually adding the changes back each time).

Thanks.
 
Yup, make the changes, and commit again. That'll update the PR.

Or I can just merge it and make the changes myself. Whichever you'd prefer.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top