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

×
×
  • Create New...