Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4] Generic Blank State for Categories of Extensions & Tags #1709

Closed
jgerman-bot opened this issue Apr 30, 2021 · 0 comments · Fixed by #1825
Closed

[4] Generic Blank State for Categories of Extensions & Tags #1709

jgerman-bot opened this issue Apr 30, 2021 · 0 comments · Fixed by #1825

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#33286 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/components/com_categories/src/Model/CategoriesModel.php b/administrator/components/com_categories/src/Model/CategoriesModel.php
index ce61b6a061837..16b67cb49c8d8 100644
--- a/administrator/components/com_categories/src/Model/CategoriesModel.php
+++ b/administrator/components/com_categories/src/Model/CategoriesModel.php
@@ -488,4 +488,32 @@ public function countItems(&$items, $extension)
 			$component->countItems($items, $section);
 		}
 	}
+
+	/**
+	 * Is this an empty state, I.e: no items of this type regardless of the searched for states.
+	 *
+	 * @return boolean
+	 *
+	 * @since __DEPLOY_VERSION__
+	 */
+	public function getisEmptyState()
+	{
+		$extension = $this->getState('filter.extension');
+
+		$sql = $this->query
+			->clear('select')
+			->clear('values')
+			->clear('bounded')
+			->clear('limit')
+			->clear('order')
+			->clear('where')
+			->select('count(*)');
+
+		$sql->where($this->_db->quoteName('extension') . ' = :extension')
+			->bind(':extension', $extension);
+
+		$this->_db->setQuery($sql);
+
+		return !($this->_db->loadResult() > 0);
+	}
 }
diff --git a/administrator/components/com_categories/src/View/Categories/HtmlView.php b/administrator/components/com_categories/src/View/Categories/HtmlView.php
index 26d6e5b4e329d..e65f75722458f 100644
--- a/administrator/components/com_categories/src/View/Categories/HtmlView.php
+++ b/administrator/components/com_categories/src/View/Categories/HtmlView.php
@@ -71,6 +71,14 @@ class HtmlView extends BaseHtmlView
 	 */
 	public $activeFilters;
 
+	/**
+	 * Is this view an Empty State
+	 *
+	 * @var  boolean
+	 * @since __DEPLOY_VERSION__
+	 */
+	private $isEmptyState = false;
+
 	/**
 	 * Display the view
 	 *
@@ -87,6 +95,12 @@ public function display($tpl = null)
 		$this->filterForm    = $this->get('FilterForm');
 		$this->activeFilters = $this->get('ActiveFilters');
 
+		// Written this way because we only want to call IsEmptyState if no items, to prevent always calling it when not needed.
+		if (!count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
+		{
+			$this->setLayout('emptystate');
+		}
+
 		// Check for errors.
 		if (count($errors = $this->get('Errors')))
 		{
@@ -141,7 +155,7 @@ protected function addToolbar()
 		$component  = $this->state->get('filter.component');
 		$section    = $this->state->get('filter.section');
 		$canDo      = ContentHelper::getActions($component, 'category', $categoryId);
-		$user       = Factory::getUser();
+		$user       = Factory::getApplication()->getIdentity();
 
 		// Get the toolbar object instance
 		$toolbar = Toolbar::getInstance('toolbar');
@@ -195,7 +209,7 @@ protected function addToolbar()
 			$toolbar->addNew('category.add');
 		}
 
-		if ($canDo->get('core.edit.state') || Factory::getUser()->authorise('core.admin'))
+		if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $user->authorise('core.admin')))
 		{
 			$dropdown = $toolbar->dropdownButton('status-group')
 				->text('JTOOLBAR_CHANGE_STATUS')
@@ -215,7 +229,7 @@ protected function addToolbar()
 				$childBar->archive('categories.archive')->listCheck(true);
 			}
 
-			if (Factory::getUser()->authorise('core.admin'))
+			if ($user->authorise('core.admin'))
 			{
 				$childBar->checkin('categories.checkin')->listCheck(true);
 			}
@@ -237,14 +251,14 @@ protected function addToolbar()
 			}
 		}
 
-		if ($canDo->get('core.admin'))
+		if (!$this->isEmptyState && $canDo->get('core.admin'))
 		{
 			$toolbar->standardButton('refresh')
 				->text('JTOOLBAR_REBUILD')
 				->task('categories.rebuild');
 		}
 
-		if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete', $component))
+		if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete', $component))
 		{
 			$toolbar->delete('categories.delete')
 				->text('JTOOLBAR_EMPTY_TRASH')
diff --git a/administrator/components/com_categories/tmpl/categories/emptystate.php b/administrator/components/com_categories/tmpl/categories/emptystate.php
new file mode 100644
index 0000000000000..03b15bdbece0b
--- /dev/null
+++ b/administrator/components/com_categories/tmpl/categories/emptystate.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @package     Joomla.Administrator
+ * @subpackage  com_categories
+ *
+ * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
+ * @license     GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+defined('_JEXEC') or die;
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\Layout\LayoutHelper;
+
+$extension = $this->state->get('filter.extension');
+$component = $this->state->get('filter.component');
+$section = $this->state->get('filter.section');
+
+// Special handling for the title as com_categories is a service component for many other components. Copied from the categories view.
+$lang = Factory::getApplication()->getLanguage();
+$lang->load($component, JPATH_BASE)
+|| $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component);
+
+// If a component categories title string is present, let's use it.
+if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? "_$section" : '')) . '_CATEGORIES_TITLE'))
+{
+	$title = Text::_($component_title_key);
+}
+// Else if the component section string exists, let's use it
+elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_$section" : ''))))
+{
+	$title = Text::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', $this->escape(Text::_($component_section_key)));
+}
+else // Else use the base title
+{
+	$title = Text::_('COM_CATEGORIES_CATEGORIES_BASE_TITLE');
+}
+
+$displayData = [
+	'textPrefix' => 'COM_CATEGORIES',
+	'formURL'    => 'index.php?option=com_categories&extension=' . $extension,
+	'helpURL'    => 'https://docs.joomla.org/Special:MyLanguage/Category',
+	'title'      => $title,
+	'icon'       => 'icon-folder categories content-categories',
+];
+
+if (Factory::getApplication()->getIdentity()->authorise('core.create', $extension))
+{
+	$displayData['createURL'] = 'index.php?option=com_categories&extension=' . $extension . '&task=category.add';
+}
+
+echo LayoutHelper::render('joomla.content.emptystate', $displayData);
diff --git a/administrator/components/com_tags/src/Model/TagsModel.php b/administrator/components/com_tags/src/Model/TagsModel.php
index 5718217c5ded5..9e077a70fbd4c 100644
--- a/administrator/components/com_tags/src/Model/TagsModel.php
+++ b/administrator/components/com_tags/src/Model/TagsModel.php
@@ -325,4 +325,29 @@ public function countItems(&$items, $extension)
 			$component->countTagItems($items, $extension);
 		}
 	}
+
+	/**
+	 * Is this an empty state, I.e: no items of this type regardless of the searched for states.
+	 *
+	 * @return boolean
+	 *
+	 * @since __DEPLOY_VERSION__
+	 */
+	public function getisEmptyState()
+	{
+		$sql = $this->query
+			->clear('select')
+			->clear('values')
+			->clear('bounded')
+			->clear('limit')
+			->clear('order')
+			->clear('where')
+			->select('count(*)');
+
+		$sql->where($this->_db->quoteName('alias') . ' != ' . $this->_db->quote('root'));
+
+		$this->_db->setQuery($sql);
+
+		return !($this->_db->loadResult() > 0);
+	}
 }
diff --git a/administrator/components/com_tags/src/View/Tags/HtmlView.php b/administrator/components/com_tags/src/View/Tags/HtmlView.php
index 9f63432d49295..0ca2d23a1378e 100644
--- a/administrator/components/com_tags/src/View/Tags/HtmlView.php
+++ b/administrator/components/com_tags/src/View/Tags/HtmlView.php
@@ -79,6 +79,11 @@ public function display($tpl = null)
 		$this->filterForm    = $this->get('FilterForm');
 		$this->activeFilters = $this->get('ActiveFilters');
 
+		if (!count($this->items) && $this->get('IsEmptyState'))
+		{
+			$this->setLayout('emptystate');
+		}
+
 		// Check for errors.
 		if (count($errors = $this->get('Errors')))
 		{
diff --git a/administrator/components/com_tags/tmpl/tags/emptystate.php b/administrator/components/com_tags/tmpl/tags/emptystate.php
new file mode 100644
index 0000000000000..04eb96caa97c5
--- /dev/null
+++ b/administrator/components/com_tags/tmpl/tags/emptystate.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * @package     Joomla.Administrator
+ * @subpackage  com_tags
+ *
+ * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
+ * @license     GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+defined('_JEXEC') or die;
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Layout\LayoutHelper;
+
+$displayData = [
+	'textPrefix' => 'COM_TAGS',
+	'formURL'    => 'index.php?option=com_tags&task=tag.add',
+	'helpURL'    => 'https://docs.joomla.org/Special:MyLanguage/J3.x:How_To_Use_Content_Tags_in_Joomla!',
+	'icon'       => 'icon-tags tags',
+];
+
+if (Factory::getApplication()->getIdentity()->authorise('core.create', 'com_tags'))
+{
+	$displayData['createURL'] = 'index.php?option=com_tags&task=tag.add';
+}
+
+echo LayoutHelper::render('joomla.content.emptystate', $displayData);
diff --git a/administrator/language/en-GB/com_categories.ini b/administrator/language/en-GB/com_categories.ini
index c14f3db50ec40..2c6da7fa8765b 100644
--- a/administrator/language/en-GB/com_categories.ini
+++ b/administrator/language/en-GB/com_categories.ini
@@ -17,6 +17,8 @@ COM_CATEGORIES_CATEGORY_BASE_EDIT_TITLE="Edit Category"
 COM_CATEGORIES_CATEGORY_EDIT_TITLE="%s: Edit Category"
 COM_CATEGORIES_DELETE_NOT_ALLOWED="Delete not allowed for category %s."
 COM_CATEGORIES_EDIT_CATEGORY="Edit Category"
+COM_CATEGORIES_EMPTYSTATE_BUTTON_ADD="Add a category"
+COM_CATEGORIES_EMPTYSTATE_CONTENT="There are currently no categories for this extension."
 COM_CATEGORIES_ERROR_ALL_LANGUAGE_ASSOCIATED="A category item set to All languages can't be associated. Associations have not been set."
 COM_CATEGORIES_FIELD_BASIC_LABEL="Options"
 COM_CATEGORIES_FIELD_IMAGE_ALT_EMPTY_DESC="Decorative Image - no description required"
diff --git a/administrator/language/en-GB/com_tags.ini b/administrator/language/en-GB/com_tags.ini
index 0bf8f9121c372..bd22faaa07263 100644
--- a/administrator/language/en-GB/com_tags.ini
+++ b/administrator/language/en-GB/com_tags.ini
@@ -34,6 +34,9 @@ COM_TAGS_COUNT_TAGGED_ITEMS_ASC="Tagged Items ascending"
 COM_TAGS_COUNT_TAGGED_ITEMS_DESC="Tagged Items descending"
 COM_TAGS_COUNT_TRASHED_ITEMS="Trashed items"
 COM_TAGS_COUNT_UNPUBLISHED_ITEMS="Unpublished items"
+COM_TAGS_EMPTYSTATE_BUTTON_ADD="Add your first tag"
+COM_TAGS_EMPTYSTATE_CONTENT="Tags in Joomla! provide a flexible way of organizing content. The same tag can be applied to many different content items across content types."
+COM_TAGS_EMPTYSTATE_TITLE="No Tags have been created yet."
 COM_TAGS_ERROR_UNIQUE_ALIAS="Another Tag has the same alias (remember it may be a trashed item)."
 COM_TAGS_EXCLUDE="Exclude"
 COM_TAGS_FIELD_CONTENT_TYPE_LABEL="Content types"
diff --git a/layouts/joomla/content/emptystate.php b/layouts/joomla/content/emptystate.php
index e6e990fd6501f..6871ea28ff3e9 100644
--- a/layouts/joomla/content/emptystate.php
+++ b/layouts/joomla/content/emptystate.php
@@ -23,6 +23,8 @@
 $formURL    = $displayData['formURL'] ?? '';
 $createURL  = $displayData['createURL'] ?? '';
 $helpURL    = $displayData['helpURL'] ?? '';
+$title      = $displayData['title'] ?? Text::_($textPrefix . '_EMPTYSTATE_TITLE');
+$content    = $displayData['content'] ?? Text::_($textPrefix . '_EMPTYSTATE_CONTENT');
 $icon       = $displayData['icon'] ?? 'icon-copy article';
 ?>
 
@@ -30,10 +32,10 @@
 
 	<div class="px-4 py-5 my-5 text-center">
 		<span class="fa-8x mb-4 <?php echo $icon; ?>" aria-hidden="true"></span>
-		<h1 class="display-5 fw-bold"><?php echo Text::_($textPrefix . '_EMPTYSTATE_TITLE'); ?></h1>
+		<h1 class="display-5 fw-bold"><?php echo $title; ?></h1>
 		<div class="col-lg-6 mx-auto">
 			<p class="lead mb-4">
-				<?php echo Text::_($textPrefix . '_EMPTYSTATE_CONTENT'); ?>
+				<?php echo $content; ?>
 			</p>
 			<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
 				<?php if ($createURL && Factory::getApplication()->input->get('tmpl') !== 'component') : ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants