User tests: Successful: Unsuccessful:
Pull Request for Issue #10191 + #10282. This PR adds a link to the front-end view of a single article in the Article: Edit view. It only works for saved articles (that have an ID) and the links are non-SEF links.
Go to Content > Articles > open an article. On top it says "Articles: Edit"
Go to Content > Articles > open an article. On top it says "Articles: Edit" plus a new icon.
A click on that icon will open the article in the front-end in a new window.
Status | New | ⇒ | Pending |
Labels |
Added:
?
?
|
Labels |
Added:
?
?
|
Category | ⇒ | Administration Language & Strings UI/UX |
Labels |
Labels |
Title |
|
It only works for saved articles (that have an ID)
Not 100% true - it only works for saved articles that have a status of published or archived.
Also the icon needs a bit of css love as the colour has little contrast to the background which is an a11y fail and the onhover is almost the same as the background
This PR is wrong as I explained here:
#10282 (comment)
Also we get a fatal error in multilang
( ! ) Fatal error: Call to undefined function array_column() in /Applications/MAMP/htdocs/testwindows/trunkgitnew/plugins/system/redirect/redirect.php on line 170
Here is a diff which will work when sef on or off, in multilang or not.
As JRoute does not work yet from admin to site, it will use a non-sef url.
I guess it is not very important as it is only to check the look of the article in frontend.
The Itemid is the one of the Home page for the language used by the item.
It will be very easy to modify when JRoute will work in admin.
No new lang string necessary as it picks the article title.
diff --git a/administrator/components/com_content/views/article/view.html.php b/administrator/components/com_content/views/article/view.html.php
index 9f58183..9e67513 100644
--- a/administrator/components/com_content/views/article/view.html.php
+++ b/administrator/components/com_content/views/article/view.html.php
@@ -87,6 +87,64 @@
$canDo = $this->canDo;
+ $linkArticle = "";
+
+ if (!$isNew)
+ {
+ $lang = '';
+ $sef = '';
+
+ // Get the home Itemid for the language
+ $db = JFactory::getDbo();
+ $query = $db->getQuery(true);
+
+ $query->select('id')
+ ->from($db->qn('#__menu'))
+ ->where($db->qn('home') . '= 1')
+ ->where($db->qn('published') . '= 1')
+ ->where($db->qn('client_id') . '= 0');
+
+ if (JLanguageMultilang::isEnabled())
+ {
+ $query->where($db->qn('language') . ' = ' . $db->q($this->item->language));
+ }
+ else
+ {
+ $query->where($db->qn('language') . ' = ' . $db->q('*'));
+ }
+ $db->setQuery($query);
+
+ $Itemid = '&Itemid=' . (int) $db->loadResult();
+
+ if ($this->item->language && JLanguageMultilang::isEnabled())
+ {
+ // Get the sef prefix for the language
+ $query->clear()
+ ->select('sef')
+ ->from($db->qn('#__languages'))
+ ->where($db->qn('published') . '= 1')
+ ->where($db->qn('lang_code') . ' = ' . $db->q($this->item->language));
+ $db->setQuery($query);
+
+ $sef = $db->loadResult();
+
+ if ($this->item->language != '*')
+ {
+ $lang = '&lang=' . $sef;
+ }
+ else
+ {
+ $lang = "";
+ }
+ }
+
+ $linkArticle = '<a href="' .
+ JURI::root() . 'index.php?option=com_content&view=article&id=' . (int) $this->item->id
+ . '&catid=' . (int) $this->item->catid . $lang . $Itemid . '" title="' . $this->item->title
+ . '" target="_blank"><span class="icon-out-2"></span></a>';
+ }
+
JToolbarHelper::title(
- JText::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE'))),
+ JText::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE')))
+ . " " . $linkArticle,
'pencil-2 article-add'
);
@infograf768 log a separate (release blocking) issue for the array_column()
error. It's unrelated to this patch and it is a release blocker because per the documentation it only exists as of PHP 5.5. Either a polyfill for the method needs to be implemented (add the symfony/polyfill-php55
package via Composer) or the code rewritten to not use that function.
Good idea but I am not a fan of the approach. Having a single icon next to the Toolbar title has no real meaning so people will not know what it does.
I think adding it below the textarea as show in the screenshot below would be better. The icon for the "toggle editor" button also really needs to change too:
An alert should also appear if the article requires saving before hand
That looks like you are previewing only description ?
but also i agree that an icon next to "Page title" is not best choice ?
I agree about the icon - I will see what I can find (for another PR)
Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/
I have tested this item
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
Status | Ready to Commit | ⇒ | Pending |
Labels |
Sorry I am removing the RTC at this time.
Labels |
Removed:
?
|
Indeed. Test were not done correctly. Once more, the language has to be included in the link... !!! See above.
Once #11060 is merged, the right code would be:
diff --git a/administrator/components/com_content/views/article/view.html.php b/administrator/components/com_content/views/article/view.html.php
index 9f58183..6bc8cce 100644
--- a/administrator/components/com_content/views/article/view.html.php
+++ b/administrator/components/com_content/views/article/view.html.php
@@ -87,6 +87,65 @@
$canDo = $this->canDo;
+ $link = "";
+ $linkArticle = "";
+
+ if (!$isNew)
+ {
+ $lang = '';
+ $sef = '';
+
+ // Get the home Itemid for the language
+ $db = JFactory::getDbo();
+ $query = $db->getQuery(true);
+
+ $query->select('id')
+ ->from($db->qn('#__menu'))
+ ->where($db->qn('home') . '= 1')
+ ->where($db->qn('published') . '= 1')
+ ->where($db->qn('client_id') . '= 0');
+
+ if (JLanguageMultilang::isEnabled())
+ {
+ $query->where($db->qn('language') . ' = ' . $db->q($this->item->language));
+ }
+ else
+ {
+ $query->where($db->qn('language') . ' = ' . $db->q('*'));
+ }
+ $db->setQuery($query);
+
+ $Itemid = '&Itemid=' . (int) $db->loadResult();
+
+ if ($this->item->language && JLanguageMultilang::isEnabled())
+ {
+ // Get the sef prefix for the language
+ $query->clear()
+ ->select('sef')
+ ->from($db->qn('#__languages'))
+ ->where($db->qn('published') . '= 1')
+ ->where($db->qn('lang_code') . ' = ' . $db->q($this->item->language));
+ $db->setQuery($query);
+
+ $sef = $db->loadResult();
+
+ if ($this->item->language != '*')
+ {
+ $lang = '&lang=' . $sef;
+ }
+ else
+ {
+ $lang = "";
+ }
+ }
+
+ $link = JRoute::_('index.php?option=com_content&view=article&id=' . (int) $this->item->id
+ . '&catid=' . (int) $this->item->catid . $lang . $Itemid , true, null, 'site');
+ $linkArticle = '<a href="' . $link . '" title="' . $this->item->title
+ . '" target="_blank"><span class="icon-out-2"></span></a>';
+ }
+
JToolbarHelper::title(
- JText::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE'))),
+ JText::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE')))
+ . " " . $linkArticle,
'pencil-2 article-add'
);
@andrepereiradasilva
As you see in my code above, I did not need
JRoute::_(ContentHelperRoute::getArticleRoute
@andrepereiradasilva
As you see in my code above, I did not need
JRoute::_(ContentHelperRoute::getArticleRoute
true, but if already exists why not just reuse it like i did in my comment?
Indeed. :)
This would be enough:|
$linkArticle = "";
$url = "";
if (!$isNew)
{
JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');
$url = JRoute::_(ContentHelperRoute::getArticleRoute((int) $this->item->id, (int) $this->item->catid, $this->item->language), true, null, 'site');
$linkArticle = '<a href="' . $url . '" title="' . htmlspecialchars($this->item->title, ENT_COMPAT, 'UTF-8') . '" target="_blank"><span class="icon-out-2"></span></a>';
}
JToolbarHelper::title(
JText::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE')))
. " " . $linkArticle,
'pencil-2 article-add'
);
I have tested this item
Status | Pending | ⇒ | Information Required |
Labels |
@pe7er will you be updating this to work with multilingual as mentioned by @infograf768 above?
@c-lodder any update?
@brianteeman - will do now. So I assume this is going into staging then?
@pe7er not sure what the status is on this PR - can you clarify please
I have tested this item
How comes this was never implemented? Seems like a no-brainer.
Status | Information Required | ⇒ | Needs Review |
Category | Administration Language & Strings UI/UX | ⇒ | Administration com_content Language & Strings UI/UX |
Status | Needs Review | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-05-13 20:12:27 |
Closed_By | ⇒ | roland-d |
btw: I've used the word "item" in the language file, and not "article".
I'll create two similar PRs for com_contact + com_newsfeeds soon, so we can reuse the language string...