Jump to content

Recommended Posts

Posted

Hi,

I've been trying to get the active status of languages to update based on other info on the page, in this case I only want a language to be active if there is a file tagged with its name:

<?php

// admin.php

$pages->addHook('saveReady', function(HookEvent $event) {
  $page = $event->arguments('page');
  foreach($event->wire()->languages->findNonDefault() as $language) {
    $key = "status$language->id";
    if($page->id) {
      $page->set($key, $page->resource->findTag($language->name)->count ? 1 : 0);
    } else {
      $page->setQuietly($key, 0);
    }
  }
});

I've tried all sorts of approaches but nothing works. It seems as if there is a Page cache issue here. Tried $pages->uncache() but that didn't seem to work either...

Anyway, I 'solved' it like so:

<?php

// admin.php

$wire->addHook('InputfieldPageName::render', function(HookEvent $event) {
	$page = $event->object->editPage;
  	if($page && $page->id) {
		foreach($event->wire()->languages->findNonDefault() as $language) {
			$page->setQuietly("status$language->id", $page->resource->findTag($language->name)->count ? 1 : 0);
		}
	}
});

It does require the user to then save the page, but it is definitely better than having all the languages active when I only need some.

Hope this is useful...

Cheers,

Chris

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...