Jump to content

Image tags and hooks


OLSA
 Share

Recommended Posts

Hello for all,

I can't find solution how to manipulate with image tags field (as object) inside admin/edit using hooks.

My problem that I need to use multilanguage predefined tags (I like to store pages ID from some another page tree).
Also I know that there are other solutions (eg. repeatable field with image field and some page field for tags, or using page table), but in my case I like to use hook inside custom module for that job.

I try with InputfieldImage::render, and InputfieldFile::render... but with that I can't get/"touch" values from image tags field.

Only working solution what I have right now is using ProcessPageEdit::execute but with that can manipulate only with tags value - is there any other better elegant solution to manipulate with image tags field (as object, as example set class, add readonly attribute, append some html...)?

$this->addHookBefore('ProcessPageEdit::execute', function(HookEvent $event) {
    $page = $event->object->getPage();
    foreach ( $page->fields as $field ) {
        if ($field->type instanceof FieldtypeImage && $field->useTags) {
            $imageField = $page->get((string)$field->name);
            // there are multiple images
            foreach($imageField as $f){
                $f->tags = '...'; // tags value	only
            }
	    }
    }
});

Regards and thanks.

 

EDIT:

Now it's clear to me what can be done. With this ("simple" variant) is possible to add class to wrapper, manipulate with value, but for more than that need to override core InputfieldFile module (inside site/modules). Also there is always option to use javascript for some manipulation.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By snck
      Hi there,
      I am trying to convince a client to use image tags in a future version of the website. The plan is to have one image container per page and use tags to differentiate between different roles (header image, gallery, slider...). I thought it would be great to show also the image tags in the backend (thumbnail) overview without having to scroll through potentially long lists or clicking on every single image to see how it is output. I could not find a setting, a module or handy little hook that accomplishes this task, but maybe you have a solution?
      Cheers,
      Flo
    • By jploch
      Hey guys,
      i want to put out a list with tags from an image field (thumbnail) of the page beeing viewed.
      The tags should link to pages, with the same name as the tags. The Tags are seperates by "|" (instead of a space).
      Here is my code (wich is not working):
      function footerProjekte(){ $alltags = $page->thumbnail->tags; echo "<ul>"; foreach($alltags as $tag) {     echo "<li><a href='{$tag}'>{$tag}</a></li>"; } echo "</ul>"; } any ideas?
      Thx!
×
×
  • Create New...