1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

Icon link in list to custom php script

Discussion in 'Community' started by achartier, Apr 17, 2018.

Thread Status:
Not open for further replies.
  1. achartier

    achartier Active Member

    Level: Community
    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.
     
  2. Sophist

    Sophist Well-Known Member

    Level: Community
  3. achartier

    achartier Active Member

    Level: Community
    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.
     
  4. Sophist

    Sophist Well-Known Member

    Level: Community
    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.
     
  5. achartier

    achartier Active Member

    Level: Community
    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.
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Community
    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.
     
  7. Sophist

    Sophist Well-Known Member

    Level: Community
    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 (Text):
    <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 (Text):
    <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.
     
  8. achartier

    achartier Active Member

    Level: Community
    Will do. I solved my script access issue, came to me in my dreams. Jumi will do all that I need.
     
  9. troester

    troester Well-Known Member Staff Member

    Level: Community
  10. achartier

    achartier Active Member

    Level: Community
    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 (Text):
    <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 (Text):
    <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 (Text):
    <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.
     
  11. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Sounds like the right approach.

    -- hugh
     
  12. achartier

    achartier Active Member

    Level: Community
    You mean a separate layout? If so I will see if I can work it up and integrate and do a pr for it.
     
  13. achartier

    achartier Active Member

    Level: Community
  14. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Does this still require the other change you made? Can't seem to find it now, but removing that replaceWithicon() call.

    -- hugh
     
  15. achartier

    achartier Active Member

    Level: Community
    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.
     
  16. achartier

    achartier Active Member

    Level: Community
    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.
     
  17. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I've added a few change requests.

    -- hugh
     
  18. achartier

    achartier Active Member

    Level: Community
    Do I need to do anything about these changes? Sorry, I have not had this before.
     
  19. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    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
     
  20. achartier

    achartier Active Member

    Level: Community
    Let me make them so I will know for future. Will do so tomorrow.
     
Thread Status:
Not open for further replies.

Share This Page