Jump to content

page labels in catalog


valan
 Share

Recommended Posts

I have a Page field that stores car pages from cars catalog.

Each page is either Make or Model or Modification depending on its place in tree. Currently I use titles for page labels as seen at picture.

The problem is that labels may have same title and its hard-to-impossible to understand car page location in tree structure by looking at field.

E.g. I need labels that say where in tree structure car page is located, smth like this -

for makes: {title}

for models: {parent.title} > {title}

for modifications: {parent.parent.title} > {parent.title} > {title}

How to do that?

post-1193-0-41894800-1442320415_thumb.jp

Link to comment
Share on other sites

Sure, somehow I imagined the topmost pages to not have parents anymore xD But the feature is still the right call. The page inputfield is calling Page::getMarkup, which you can simply hook. In the field settings just use insert "MySpecialLabelKey" or whatever string you want to init the hook.

$wire->addHookBefore("Page::getMarkup", function($event){
  $page = $event->object;
  $key = $event->arguments(0);

  if($key == "MySpecialLabelKey"){
    if($page->template == "manufacturer") $key = "{title}";
    if($page->template == "model") $key = "{parent.title} {title}";
  }

  $event->arguments(0, $key);
});
  • Like 1
Link to comment
Share on other sites

In the field settings just use insert "MySpecialLabelKey" or whatever string you want to init the hook.

I've copied code to admin.php and placed MySpecialLabelKey string to "Custom page label format" but it still doesn't work.

Is "Custom page label format" the right place to insert the string? 

Link to comment
Share on other sites

Yes, this is strange. Looks like hook doesn't trigger...

I've added wire()->log->error('Im here!'); at second line but it doesn't log anything.

wire()->addHookBefore('Page::getMarkup', function($event) {

    wire()->log->error('Im here!');

    $page = $event->object;
    $key  = $event->arguments(0);

    if ($page->template != 'service') return;

    if ($key == 'MySpecialLabelKey') // service_exclude_cars
    {
        if($page->template == 'vehicle-make') $key = '{title}';
        if($page->template == 'vehicle-modelGroup') $key = '{parent.title} > {title}';
        if($page->template == 'vehicle-model') $key = '{parent.title} > {parent.title} > {title}';
    }

    $event->arguments(0, $key);
});
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.
×
×
  • Create New...