LanguageSupportPageNames::pageNotAvailableInLanguage()

Called when page is not available in a given language

Hook this method to change the behavior of what happens when a Page is requested in a language that it is not marked as active in.

  • Return boolean true if it should render the page anyway (like for editing user).
  • Return boolean false if it should throw a “404 Page Not Found”.
  • Return string containing URL like /some/url/ if it should redirect to given URL.
  • Return array [ 302, '/some/url/' ] if it should do a 302 “temporary” redirect to URL.
  • Return array [ 301, '/some/url/' ] if it should do a 301 “permanent” redirect to URL.

Available since version 3.0.186.

Usage

$bool = $languageSupportPageNames->pageNotAvailableInLanguage(Page $page, Language $language);

Arguments

NameType(s)Description
$pagePage
$languageLanguage

Return value

bool array


Hooking LanguageSupportPageNames::pageNotAvailableInLanguage(…)

You can add your own hook events that are executed either before or after the LanguageSupportPageNames::pageNotAvailableInLanguage(…) method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.

Hooking before

The 'before' hooks are called immediately before each LanguageSupportPageNames::pageNotAvailableInLanguage(…) method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.

$this->addHookBefore('LanguageSupportPageNames::pageNotAvailableInLanguage', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $LanguageSupportPageNames = $event->object;

  // Get values of arguments sent to hook (and optionally modify them)
  $page = $event->arguments(0);
  $language = $event->arguments(1);

  /* Your code here, perhaps modifying arguments */

  // Populate back arguments (if you have modified them)
  $event->arguments(0, $page);
  $event->arguments(1, $language);
});

Hooking after

The 'after' hooks are called immediately after each LanguageSupportPageNames::pageNotAvailableInLanguage(…) method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.

$this->addHookAfter('LanguageSupportPageNames::pageNotAvailableInLanguage', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $LanguageSupportPageNames = $event->object;

  // An 'after' hook can retrieve and/or modify the return value
  $return = $event->return;

  // Get values of arguments sent to hook (if needed)
  $page = $event->arguments(0);
  $language = $event->arguments(1);

  /* Your code here, perhaps modifying the return value */

  // Populate back return value, if you have modified it
  $event->return = $return;
});

LanguageSupportPageNames methods and properties

API reference based on ProcessWire core version 3.0.269