? ? ? Pending

User tests: Successful: Unsuccessful:

avatar Bakual
Bakual
11 Aug 2017

As mentioned in Issue #17415, the sample data is not language aware. The data is just installed with the language set to * (All).
This PR would change the blog sample data set so it installs the content with the currently active language flagged if the site is a multilingual site. Otherwise it will still install the data as *.

Summary of Changes

On multilingual sites, the active language will be used to tag the content.

Testing Instructions

Install the blog sample data on a multilingual site and on a monolingual site.

Expected result

Monolingual: Data is installed with language "*"
Multilingual: Data is installed with active language

Actual result

Data is always installed with langiage "*"

Documentation Changes Required

None

avatar joomla-cms-bot joomla-cms-bot - change - 11 Aug 2017
Category Front End Plugins
avatar Bakual Bakual - open - 11 Aug 2017
avatar Bakual Bakual - change - 11 Aug 2017
Status New Pending
avatar Bakual
Bakual - comment - 11 Aug 2017

@infograf768 What do you think?

avatar infograf768
infograf768 - comment - 11 Aug 2017

will test tomorrow. i have to test what happens when one switches languages in admin and installs again the blog sample data. my first thought is that the names of items should be amended with (xx-XX). Also that the description of the sample data displayed in the module should explain this feature when in multilang.

avatar Bakual
Bakual - comment - 11 Aug 2017

If the sample data is not translated and thus has the same name, then it will refuse to install due to duplicate alias.
We could add code to add the language tag to the alias indeed. That would work around this potential issue.

avatar infograf768
infograf768 - comment - 11 Aug 2017

This is what I have done. It works fine. I installed blog sample data in both en-GB and when fr-FR is admin language. There is not yet any fr-FR ini for the blog, thus why the titles and contents are still in English. Here for categories.

screen shot 2017-08-11 at 17 56 30

I still need to solve some issues

BTW, I added this code where it should be:
$lang_suffix = Multilanguage::isEnabled() ? ' (' . strtolower(JFactory::getLanguage()->getTag()) . ')' : '';

and for example

$categoryTitle = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_0_TITLE') . $lang_suffix;

avatar infograf768
infograf768 - comment - 11 Aug 2017

The issues I have to solve concerns the catid for the blog menu item (I always get index.php?option=com_content&view=category&layout=blog&id=9 and the homes when they are already set when installing the site as multilang (need to keep the default Homes already created)

avatar infograf768
infograf768 - comment - 12 Aug 2017

Solved the last issues.
Now the blog uses as id the specific catid and not a hardcoded one (this was imho also a bug in monolingual)
And, in multilingual, if it exists, it keeps the language Home menu item that was created when installing Joomla or later on.

blog.php.zip

screen shot 2017-08-12 at 07 41 48

@Bakual Please download the zip and test.

avatar AlexRed
AlexRed - comment - 13 Aug 2017

JM's proposal work for me

avatar Bakual
Bakual - comment - 13 Aug 2017

@infograf768 Few questions:

  • Is there a reason you force the tag to lowercase? Imho we can just leave it at eg fr-FR, or not?
    I think we can also move it to the code where the content is actually pushed to the model, so we don't have to add the suffix to each item individually.

  • If we don't change the home menuitem for multilingual, we can also just remove it from monolingual as well. It's something that isn't necessary to be present in the sample data. We could decide to just remove the home menuitem creation/handling from the plugin and leave the current home menuitems as is.

  • The category thing indeed was a bug. Thanks for detecting and fixing!

avatar infograf768
infograf768 - comment - 13 Aug 2017

@Bakual
lowercase: I just did as we do when we install J as multilingual , keeping the tag as is is ok.
If you find a way to simplify the code, I am all for it.

home: the idea was that one could install a new language, switch to that language in admin and then also install this sample data. The home for this new language (which has nothing yet in db) would be taken care of by the plugin.

i did not try in my proposal to also publish the new content language in that case.
it should be possible.

avatar infograf768
infograf768 - comment - 14 Aug 2017

Concernng home, just remarked my code does not set the new language Blog Home page menu item to home. I may have an error in my code.

// Keep a multilingual "Home" menu item if it already exists
		else
		{
			if ($menuItemTable->load(
				array(
					'home'     => 1,
					'language' => $language,
				) != null))
			{	
				$home = 0;
			}
			else
			{
				$home = 1;
			}
		}
avatar infograf768
infograf768 - comment - 14 Aug 2017

That part should be

// Keep a multilingual "Home" menu item if it already exists
		else
		{
			if ($menuItemTable->load(
				array(
					'home'     => 1,
					'language' => $language,
				)))
			{	
				$home = 0;
			}
			else
			{
				$home = 1;
			}
		}

?

avatar infograf768
infograf768 - comment - 14 Aug 2017

@Bakual
To publish the content language for a newly installed language, where could we put this code (or similar)?

		if (Multilanguage::isEnabled()
		{
			$db = JFactory::getDbo();
			$db->setQuery(
				$db->getQuery(true)
					->update('#__languages')
					->set('published = 1')
					->where($db->quoteName('lang_code') . ' = ' . $db->quote($language))
			)->execute();
		}

I added it to step2 to check if it was working, and it does.

avatar infograf768
infograf768 - comment - 14 Aug 2017

@Bakual
Ok, solved it by adding a new step which publishes the Content Language

blog.php.zip

I now get correctly (strings not added yet)

screen shot 2017-08-14 at 17 32 58

Needs some iron out (strings, methods comments), but other wise we should be good.

avatar Bakual
Bakual - comment - 14 Aug 2017

Just to be clear, the purpose of this PR isn't to set up a multilingual site. It just should install the data with the correct language.
If home or the content language is missing for the active language, then it should not magically fix that.

We can add code to set up a multilingual site, but it should be an own plugin, not the blog one. In that plugin we could then also take care of association and everything.

avatar infograf768
infograf768 - comment - 14 Aug 2017

I guess my proposal is now fine and will provide blog sample data when the site is multilingual and the sample is installed for any existing language by just switching admin language.
No assoc but making sure we have a home (existing already or not) for any language, even those installed later on. Also making sure the Content language is published.
I guess this is the minimum we can expect from such a sample data plugin.

When the site is multilingual, it should show on frontend, which it now does correctly.

avatar Bakual Bakual - change - 15 Aug 2017
Labels Added: ?
avatar Bakual
Bakual - comment - 15 Aug 2017

Added some improvements and bugfixes suggested by @infograf768

  • I removed the "home" handling. I think it's actually better if we don't mess with the home menuitem anyway. Less risk for the user ?
  • I didn't add the content language handling JM suggested. Imho, we should just add the content and not try to fix the multilingual site setup. Maybe we should instead add a check if the content language is active and if not apply the language "All" (*) to the items. This would be possible but makes the code more complex and imho doesn't have much value.
avatar infograf768
infograf768 - comment - 17 Aug 2017

Frustrating that homes are not set as can be easily done with my patch.
In any case, some strings have to be modified.

PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE="Blog Home"

As this is not a Home anymore, I guess "Blog" would be enough.
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE="Blog"

Also
PLG_SAMPLEDATA_BLOG_OVERVIEW_DESC="Sample data which will set up a blog site."

should be modified to explain what happens when using this blog sample data on a multilingual site.

avatar Bakual
Bakual - comment - 17 Aug 2017

Frustrating that homes are not set as can be easily done with my patch.

Imho, we should rather add an own sample data plugin which will completely set up a site as a multilingual site. Better than shoving such logic into a pluzgin which has a different purpose.

should be modified to explain what happens when using this blog sample data on a multilingual site.

All it does is creating the content with the active language. Does this really need to be written in the description? I have a feeling we end up with a wall of text then.

avatar brianteeman
brianteeman - comment - 17 Aug 2017

or simply use isMultilang to remove the option to install the sample data on a multilingual site

PLEASE no walls of text

avatar infograf768
infograf768 - comment - 17 Aug 2017

or simply use isMultilang to remove the option to install the sample data on a multilingual site

In that case, this PR is totally useless... and we should just prevent the module from displaying this plugin as it is not multilang aware.

Let's say we keep it, not informing the NEWBIE (a trained user would never need to install sample data) that, in multilang, one has to switch language in admin and install the sample data for each of the installed languages, makes it a very much hidden feature.

Enough fighting against windmills for me.

avatar infograf768
infograf768 - comment - 18 Aug 2017

Too much opposition here. If no explanation to the user, let's not indeed make blog and testing installable on a multilingual site. (some bugs also corrected here)
Code proposed:

diff --git a/administrator/modules/mod_sampledata/helper.php b/administrator/modules/mod_sampledata/helper.php
index a266856..d59cec5 100644
--- a/administrator/modules/mod_sampledata/helper.php
+++ b/administrator/modules/mod_sampledata/helper.php
@@ -10,4 +10,6 @@
 defined('_JEXEC') or die;
 
+use Joomla\CMS\Language\Multilanguage;
+
 /**
  * Helper for mod_sampledata
@@ -30,4 +32,13 @@
 		$data = $dispatcher->trigger('onSampledataGetOverview', array('test', 'foo'));
 
+		// Do not display the sample data when it is not specifically optimized for a multilingual site
+		foreach ($data as $sample => $sampledata)
+		{
+			if (Multilanguage::isEnabled() && $sampledata->multilang == 0)
+			{
+				unset($data[$sample]);
+			}
+		}
+
 		return $data;
 	}
diff --git a/plugins/sampledata/blog/blog.php b/plugins/sampledata/blog/blog.php
index b294605..b744327 100644
--- a/plugins/sampledata/blog/blog.php
+++ b/plugins/sampledata/blog/blog.php
@@ -69,4 +69,7 @@
 		$data->steps       = 3;
 
+		// This sample data is not optimized for a multilingual site
+		$data->multilang   = 0;
+
 		return $data;
 	}
@@ -334,5 +337,5 @@
 		$menuItemTable->load(
 			array(
-				'home' => 1,
+				'home'     => 1,
 				'language' => '*',
 			)
@@ -341,4 +344,7 @@
 		$menuItemTable->store();
 
+		// Get previously entered categories ids
+		$catids = $this->app->getUserState('sampledata.blog.articles.catids');
+
 		// Insert menuitems level 1.
 		$menuItems = array(
@@ -346,5 +352,5 @@
 				'menutype'     => $menuTypes[0],
 				'title'        => JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'),
-				'link'         => 'index.php?option=com_content&view=category&layout=blog&id=9',
+				'link'         => 'index.php?option=com_content&view=category&layout=blog&id=' . $catids[0],
 				'component_id' => 22,
 				'home'         => 1,
@@ -869,9 +875,9 @@
 		{
 			// Set values which are always the same.
-			$module['id']              = 0;
-			$module['asset_id']        = 0;
-			$module['language']        = '*';
-			$module['note'] = '';
-			$module['published'] = 1;
+			$module['id']         = 0;
+			$module['asset_id']   = 0;
+			$module['language']   = '*';
+			$module['note']       = '';
+			$module['published']  = 1;
 			$module['assignment'] = 0;
 

blog_sample

Note: I also added $data->multilang = 0; to the testing sample data.

avatar Bakual
Bakual - comment - 18 Aug 2017

I don't see any reason to prevent the sample data being installed on a multilingual site.
Neither with or without this PR.

avatar infograf768
infograf768 - comment - 18 Aug 2017

@Bakual
It may be still a good idea to add my proposed code to this PR, setting $data->multilang = 1;
( testing sample data set to 0) as this would be useful for 3rd party or even future core sample datas.

and, in any case, modifying the strings I suggested above in #17488 (comment) to be sure newbies understand what they get.

avatar joomla-cms-bot joomla-cms-bot - change - 18 Aug 2017
Category Front End Plugins Administration Language & Strings Front End Plugins
avatar Bakual
Bakual - comment - 18 Aug 2017

Removed the "Home" part from "Blog Home".

As for the multilang property. I honestly still don't see the issue you're trying to solve here. I don't see how it is worse when you install the sample data on a multilingual site than on a monolingual one. Even if the set isn't "optimised". All you get is a bunch of data, either tagged to a specific language or to "All". "All" works both in a multilingual and a monolingual site. And it's exactly the same work to remove the data again afterwards.

avatar joomla-cms-bot joomla-cms-bot - change - 21 Aug 2017
Category Front End Plugins Administration Language & Strings Administration Language & Strings Modules Front End Plugins
avatar Bakual Bakual - change - 21 Aug 2017
Labels Added: ?
avatar Bakual
Bakual - comment - 21 Aug 2017

With latest commit I expanded the description of the sample data set to include a sentence about the behavior when the site is multilingual. It reads now

Sample data which will set up a blog site.
If the site is multilingual, the data will be tagged to the active backend language.

I think that's good enough without getting a wall of text.

avatar infograf768 infograf768 - test_item - 22 Aug 2017 - Tested successfully
avatar infograf768
infograf768 - comment - 22 Aug 2017

I have tested this item successfully on 785811f

Needs documentation.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17488.

avatar Bakual
Bakual - comment - 22 Aug 2017

I've started some basic documentation as a wiki in the testing sample data plugin repo.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 27 Aug 2017

@AlexRed can you please retest?

avatar AlexRed AlexRed - test_item - 27 Aug 2017 - Tested successfully
avatar AlexRed
AlexRed - comment - 27 Aug 2017

I have tested this item successfully on 785811f

Patch ok for me


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17488.

avatar franz-wohlkoenig franz-wohlkoenig - change - 27 Aug 2017
Status Pending Ready to Commit
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 27 Aug 2017

RTC after two successful tests.

avatar mbabker mbabker - change - 27 Aug 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-08-27 16:06:35
Closed_By mbabker
Labels Added: ?
avatar mbabker mbabker - close - 27 Aug 2017
avatar mbabker mbabker - merge - 27 Aug 2017

Add a Comment

Login with GitHub to post a comment