Jump to content

Page reference "New pages created from field" not working/indexed with multi language?


Flashmaster82
 Share

Recommended Posts

I have a field "page reference" name: tags. I have a template that it reference to. In the field i have checked "Allow new pages to be created from field" But when i create a new page from that field only the default language "i have two", is indexed. When i switch to my other language site.com/en/ the new page "tag" will not show up? If i manually add a new page with the template "tag" it will show up on both languages on the page?

Link to comment
Share on other sites

@Flashmaster82 I guess the new page is not activated in your non-default language? Check the settings tab for that. There is a checkbox on the right side of the second language name field.

I never experienced this when using the page reference field in the backend, only when you create pages via API/Hooks, you have to activate non-default languages.

Is the superuser creating pages via the field using the default language?

Link to comment
Share on other sites

Hi, I believe, I have run into some similar issue. I am creating new pages using the API, something like that:

$newPage = $pages->newPage([
    'template' => '...',
    ...
]);

$newPage->set(...);
...

$newPage->addStatus(Page::statusUnpublished);

foreach($languages->findNonDefault() as $language) $newPage->set("status$language", Page::statusOn);

$newPage->save();

If it wasn't for the foreach-loop, the new page is only active in the default language. You can find the checkbox @ngrmm is talking about here:

Page edit screen >> Settings >> Name

There, the page name is displayed for each language and at the end of the non-default ones, you find said checkbox. This is exactly what my foreach-loop is "checking".

Maybe there is an oversight in the Language Support module @ryan? Creating the very same pages in the admin enables the languages by default! Shouldn't the API do the same?

@Flashmaster82 is the checkbox marked for you? If not, you might have run into the same "bug" I have...

Link to comment
Share on other sites

Yes I know. You should see the Ekonomi and Finans pages somewhere in the page tree. Depends on how you configured your field.

Go to find Ekonomi and edit it via the tree. There you will find the Settings tab and checkbox as described. Is it checked? 

  • Like 1
Link to comment
Share on other sites

Exactly, I was going to suggest something like that. But be aware of any side effects this might have because this will act on ANY page added and renders the checkmarks on the "Add New Page" screen useless.

You might want the hook to be a bit more specific e.g. 

$wire->addHookAfter('Pages::added(0:template=_YOUR_TAGS_TEMPLATE_NAME_)', ...

or also

$wire->addHookAfter('Pages::added', function($event) {
  $page = $event->arguments(0);

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

  foreach ($this->wire->languages as $lang) $page->set("status$lang", 1);
  $page->save();
});

Still, the better solution would be to eliminate this inconsistency in core / core modules.

EDIT: You should only do this for non-default languages, e.g. with $languages->findNonDefault():

$wire->addHookAfter('Pages::added(...)', function($event) {
  ...
  foreach ($languages->findNonDefault() as $lang) $page->set("status$lang", 1);
  ...
});

 

Edited by poljpocket
  • Like 1
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...