Jump to content

Page field - New page active url in different language


Recommended Posts

Hi guys,

i'm working on a multi language website (italian and english) . I'm trying to create a simple tag system using a page as tags container and its children pages as tags. Then in my news template i'm using a page field that allows new pages to be created from this field. 

Now, everything works fins but when i create a new tag using the page field it actually creates a news page but the name for the second language is not active (see the attached image).

If i create a new page using the pages tree the active checkout is already checked.

Is there a way to make it automatically active everytime a new page is created using the page field?

Thanks a lot

post-2122-0-80493800-1435327138_thumb.pn

Link to comment
Share on other sites

I'm having the same issue and there are a couple of related issues. I have an autocomplete Page field to add tags (also tried AsmSelect and other types).

  • only the default language "title" is saved
  • field "name" is saved properly only if the admin user language is set to the default language
  • auto "name" generation works only if user lang == default lang (eg. from "title" field, in template Family - Name format for children)
  • non-default language is not activated

It's really annoying. I think I have to set up one field for each language but I guess I won't get away without a hook even so.

Link to comment
Share on other sites

The problem lies mostly in the interface. It's just not possible to reliably set up multi-language pages by using this textarea. The implementation may be flawed, but really the whole process of adding pages is not great. If you really want those tags to be translated you still need to open the tag's page and add translations. At this point you could've also added the whole thing manually. Not activating the default language makes sense, as the core cannot be certain, that users want untranslated content to show up. As the function creating the pages is already hookable Ryan should just return the new pages and everyone could hook after the creation and add their own logic.

Link to comment
Share on other sites

I agree, but from the client's POV it is not so convenient to add tags, then go to tags and translate. This would be the best, however, considering the available features.

I have only 2 languages now and solved this with 2 fields relatively easily but it's not nice.

I'm still hesitating on

- forcing the client to translate tags manually, or

- save only simple text fields (so no Tags pages to create at all)

or leave as it is.

Link to comment
Share on other sites

Another possible and very useful solution could be a field that works like a page field when you choose and existing page but works like a page table field when you create a new one. That would be great not just in this case but in a lot of other cases i can think of. But probably the easiest solution for now is trying to understand if we can change some pw core file to get that result.

Link to comment
Share on other sites

Maybe it's already possible. I'm just not sure if the variable will be available to the hook.

wire()->addHookAfter("InputfieldPage::processInputAddPages", function($event){
  $inputfield = $event->object;
  $addedPages = $inputfield->pagesAdded;

  // Change what you need to
});
Link to comment
Share on other sites

The problem is that not only different page titles are needed but page names too. And another twist is that users may want to add completely different tags per language to a page.

Link to comment
Share on other sites

  • 6 months later...

As of PW 2.5.14 you can just copy a wire module to you /site/modules/ folder, make changes and you're good to go (just mentioning ;-) blog post: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/)

So I copied InputfieldPage.module and added a few lines (in the code commented with "added by Can" without quotes)

My tags field uses InputfieldPageAutocomplete now when entering a tag which isn't present and I'm going to create it, I just enter a colon (:) after the title and enter the german one like

EnglishTagTitle:DeutscherTagTitel

Maybe not the best when you got more languages, but for me it works right now :-)

Feel free to copy and of cause adjust anything to fit your needs

Make sure to adjust the language in Line 617

Ah, and it's of cause activating the german url as well (regardless if you enter a translation or not..)

Here you go: https://gist.github.com/CanRau/e07307fbb5f8daf2c698

Link to comment
Share on other sites

  • 3 years later...

I had the same problem, hope this will help someone. :)

I have a multi language website with templates containing a page field called Tags, that the user can create on the fly.

Here's a quick way to activate the secondary languages when a new tag is created, using the cool IftRunner module. 

  1. Install the module https://github.com/ryancramerdesign/IftRunner
  2. Create a .module name inside /site/modules/IftRunner using the code below.
  3. Install this module "IftActionActivePageLanguages" you just created
  4. Go to Setup > Trigger/Action inside the admin dashboard
  5. Create a new trigger for a "Pages::saved" hook like the one shown in the screenshot.
 
 
 
 
Spoiler

<?php

require_once(dirname(__FILE__) . '/IftRunner.module');

class IftActionActivePageLanguages extends IftActionModule implements Module {

	public static function getModuleInfo() {
		return array(
			'title' => 'Activate all page languages',
			'summary' => 'When a page is created using a Page Field, only its default language is activated. This action activates the other languages',
			'version' => 1,
			'author' => 'Sérgio Jardim',
			'requires' => 'IftRunner',
			);
	}


	public function ___action($item) {
        
	    $item->setOutputFormatting(false);
        
        $languages = wire('languages');

        foreach($languages as $lang) {
            if($lang->isDefault()) continue;
            $item->set("status$lang", 1);            
            $item->save();
            $this->message("All languages activated for page ".$item->url);
        }
        


	}

}

 

image.thumb.png.71a5962d492559b2ddadfeb1f733a439.png

  • Like 4
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...