Skip to content

Commit

Permalink
[4] Empty state for com_redirect (#33384)
Browse files Browse the repository at this point in the history
* Empty state for com_redirect

* merge from other pr

* change icon

* cs

* alpha

* Update administrator/language/en-GB/com_redirect.ini

Co-authored-by: Quy <quy@fluxbb.org>

* Update administrator/components/com_redirect/tmpl/links/emptystate.php

Co-authored-by: Brian Teeman <brian@teeman.net>

Co-authored-by: Quy <quy@fluxbb.org>
Co-authored-by: Brian Teeman <brian@teeman.net>
  • Loading branch information
3 people committed Apr 30, 2021
1 parent 1293461 commit 770e24b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
19 changes: 16 additions & 3 deletions administrator/components/com_redirect/src/View/Links/HtmlView.php
Expand Up @@ -94,6 +94,14 @@ class HtmlView extends BaseHtmlView
*/
public $activeFilters;

/**
* Is this view an Empty State
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
private $isEmptyState = false;

/**
* Display the view.
*
Expand All @@ -114,8 +122,13 @@ public function display($tpl = null)
$this->activeFilters = $this->get('ActiveFilters');
$this->params = ComponentHelper::getParams('com_redirect');

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
{
$this->setLayout('emptystate');
}

// Check for errors.
if (count($errors = $this->get('Errors')))
if (\count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
Expand Down Expand Up @@ -151,7 +164,7 @@ protected function addToolbar()
$toolbar->addNew('link.add');
}

if ($canDo->get('core.edit.state') || $canDo->get('core.admin'))
if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $canDo->get('core.admin')))
{
$dropdown = $toolbar->dropdownButton('status-group')
->text('JTOOLBAR_CHANGE_STATUS')
Expand Down Expand Up @@ -194,7 +207,7 @@ protected function addToolbar()
->listCheck(true);
}

if (!$state->get('filter.state') == -2 && $canDo->get('core.delete'))
if (!$this->isEmptyState && (!$state->get('filter.state') == -2 && $canDo->get('core.delete')))
{
$toolbar->confirmButton('delete')
->text('COM_REDIRECT_TOOLBAR_PURGE')
Expand Down
46 changes: 46 additions & 0 deletions administrator/components/com_redirect/tmpl/links/emptystate.php
@@ -0,0 +1,46 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_redirect
*
* @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\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;

$displayData = [
'textPrefix' => 'COM_REDIRECT',
'formURL' => 'index.php?option=com_redirect&view=links',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help4.x:Redirects:_Links',
'icon' => 'icon-map-signs redirect',
];

$user = Factory::getApplication()->getIdentity();

if ($user->authorise('core.create', 'com_redirect'))
{
$displayData['createURL'] = 'index.php?option=com_redirect&task=link.add';
}

if ($user->authorise('core.create', 'com_redirect')
&& $user->authorise('core.edit', 'com_redirect')
&& $user->authorise('core.edit.state', 'com_redirect'))
{
$displayData['formAppend'] = HTMLHelper::_(
'bootstrap.renderModal',
'collapseModal',
[
'title' => Text::_('COM_REDIRECT_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer'),
],
$this->loadTemplate('batch_body')
);
}

echo LayoutHelper::render('joomla.content.emptystate', $displayData);
3 changes: 3 additions & 0 deletions administrator/language/en-GB/com_redirect.ini
Expand Up @@ -22,6 +22,9 @@ COM_REDIRECT_DEFAULT_IMPORT_STATE_LABEL="Import State"
COM_REDIRECT_DISABLE_LINK="Disable Link"
COM_REDIRECT_EDIT_LINK="Edit Link #%d"
COM_REDIRECT_EDIT_PLUGIN_SETTINGS="Edit Plugin Settings"
COM_REDIRECT_EMPTYSTATE_BUTTON_ADD="Add new link"
COM_REDIRECT_EMPTYSTATE_CONTENT="Redirect URLs for web pages that no longer exist on your website to web pages that are working."
COM_REDIRECT_EMPTYSTATE_TITLE="Redirects: Links"
COM_REDIRECT_ENABLE_LINK="Enable Link"
COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED="The redirect must have a destination URL"
COM_REDIRECT_ERROR_DUPLICATE_OLD_URL="The source URL must be unique."
Expand Down
10 changes: 10 additions & 0 deletions layouts/joomla/content/emptystate.php
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

Expand All @@ -26,6 +27,9 @@
$title = $displayData['title'] ?? Text::_($textPrefix . '_EMPTYSTATE_TITLE');
$content = $displayData['content'] ?? Text::_($textPrefix . '_EMPTYSTATE_CONTENT');
$icon = $displayData['icon'] ?? 'icon-copy article';
$append = $displayData['formAppend'] ?? '';
$title = $displayData['title'] ?? Text::_($textPrefix . '_EMPTYSTATE_TITLE');
$content = $displayData['content'] ?? Text::_($textPrefix . '_EMPTYSTATE_CONTENT');
?>

<form action="<?php echo Route::_($formURL); ?>" method="post" name="adminForm" id="adminForm">
Expand All @@ -50,6 +54,12 @@ class="btn btn-outline-secondary btn-lg px-4"><?php echo Text::_('JGLOBAL_LEARN_
</div>
</div>

<?php
// Allow appending any modals (Eg: Bulk Import on com_redirect).
echo $append;
?>

<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</form>

0 comments on commit 770e24b

Please sign in to comment.