Jump to content

Module: ImageMarker Fieldtype & Inputfield


kongondo

Recommended Posts

15 hours ago, Roych said:

<h3><a href="<?=$pages->get((int) $dot->value->url);?>"><?= $dot->infoLabel;?></a></h3>

There is no variable value in this module's API. The page id is at the variable info. So:

<? php
  
	$pageReferencedByMarker = $pages->get((int) $dot->info);
	// do something with $pageReferencedByMarker

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

38 minutes ago, kongondo said:

There is no variable value in this module's API. The page id is at the variable info. So:


<? php
  
	$pageReferencedByMarker = $pages->get((int) $dot->info);
	// do something with $pageReferencedByMarker

 

I think I got it ?

<?php $pageReferencedByMarker = $pages->get((int) $dot->info);?>
<a href="<?=$pageReferencedByMarker->url?>"><h4><?= $dot->infoLabel;?></h4></a>
<?php {};?>

This works, thank you ?

R

Link to comment
Share on other sites

  • 2 years later...

I am in the need of using this module in a current project 🙂

Turns out it works just as fine as I could ever wish! Except one thing:

I want to make use of Repater Field Items as selectable pages only.

So I added this line of code in the field settings. The page ID in this case is my repeater field that contains the child elements (=pages) that I want to be able to select.

image.png.5196a4e7f46f1bca610224451b9bb71c.png

This works but unfortunately I see only the page IDs in the AsmSelect Inputfield as labels:

image.png.1b6a84bc3556b141ac402184c9bc2cdb.png

I know that there is a setting for the AsmSelect to tell which field to use for the label:

image.png.b3e46800a646e1dbba33b4c71d7c6763.png

BUT since the AsmSelect in the ImageMarker module is generated via API code it is not possible to adjust this setting.

@kongondo can you help me out on this one? it is somehow possible to tell the AsmSelect which field to use as a label?

 

Link to comment
Share on other sites

I guess the module uses something like $page->get('title|id') for the labels and since your page has no title field it falls back to the id.

You can easily overwrite the "title" property of your page via hook! In this example I overwrite it for the "repeater_rpb_textgrid_items" template and set it to display the field "rpb_textgrid_headline" instead of "title":

<?php
$wire->addHookProperty("Page(template=repeater_rpb_textgrid_items)::title", function ($event) {
  $event->return = $event->object->rpb_textgrid_headline;
});

 

Link to comment
Share on other sites

On 9/9/2023 at 10:39 AM, bernhard said:

I guess the module uses something like $page->get('title|id') for the labels and since your page has no title field it falls back to the id.

You can easily overwrite the "title" property of your page via hook! In this example I overwrite it for the "repeater_rpb_textgrid_items" template and set it to display the field "rpb_textgrid_headline" instead of "title":

<?php
$wire->addHookProperty("Page(template=repeater_rpb_textgrid_items)::title", function ($event) {
  $event->return = $event->object->rpb_textgrid_headline;
});

 

That's an interesting approach. The repeater items are located here in this case (rep_stories), how would I hook into the title rendering function in this case?
image.thumb.png.93c26dae547d8ad12c991cc4fe08b5b7.png

Link to comment
Share on other sites

2 hours ago, bernhard said:

 

Ah sorry, my bad! This is not what I meant.

I want to make the headline field of the repeater item pages shown in my screenshot to be listed in the AsmSelect Inputfield of the Image Marker Field.

Right now this AsmSelect Field is only showing the page ID's of the repeater item pages:

image.png.97d67e8911e9cddaef37b394005d490e.png

I don't know if this is even possible via hook.

Link to comment
Share on other sites

I now changed Line 322 in InputfieldImageMarker.module from

$addInfoPages = $modules->get('InputfieldAsmSelect');

foreach($opts as $opt) $addInfoPages->addOption($opt->id, $opt->title);

to:

$addInfoPages = $modules->get('InputfieldAsmSelect');

foreach($opts as $opt) $addInfoPages->addOption($opt->id, $opt->headline);

Now the headline is shown as title in the select field:

image.png.679285be19bcaa66f784c5da89649cee.png

But the bummer is: It turns out that this field does not work properly inside a repeater matrix. The table with the marker coordinates never shows up after saving 😞

Link to comment
Share on other sites

I thought that repeater pages have their own template, sorry. If that's not the case then just modify my hook to check the page's parents:

Here the $page is a repeater item. You can inspect its parents like shown in line 1 and you can add something like shown in line 2 into your hook to only fire that hook that overrides the title if the parents have your repeater parent page. If not, then early exit of that hook.

eUYI0de.png

<?php
$wire->addHookProperty("Page::title", function ($event) {
  $page = $event->object;
  if(!$page->parents->has("name=for-field-157") return;
  $event->return = $event->object->headline;
});

 

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

I've inherited a site using this module and I'm seeing the integer rounding issue for marker positioning. I've read the other issues here and it looks like all the changes have been made in the code and database, AND I can see non-integer values in the database, but when I save any new ones they get rounded! Anyone have any ideas? 

Link to comment
Share on other sites

Finally found it, in getDatabaseSchema in FieldtypeImageMarker.module

		// our coordinates fields
        $schema['x'] = 'FLOAT NOT NULL DEFAULT 0'; 
        $schema['y'] = 'FLOAT NOT NULL DEFAULT 0';

        // indexes, for any fields that need to be searchable from selectors
        $schema['keys']['data'] = 'KEY data(data)';
        //$schema['keys']['x'] = 'KEY x(x)';
        //$schema['keys']['y'] = 'KEY y(y)';

Change x and y to FLOAT and I commented out their indexes since floats don't index well (i think)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...