Skip to content

Commit

Permalink
Update for Joomla 4.2 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdion authored Mar 8, 2023
1 parent bd30cb9 commit 885a19e
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 165 deletions.
5 changes: 3 additions & 2 deletions .idea/copyright/Nicholas.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions .idea/sortbyfield.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Sort By Field 2.0.0
================================================================================
~ Updated for Joomla 4.2 or later, PHP 8.0 or later
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Sort by Field

A Joomla 3 plugin to sort the articles in a category by the value of a custom field.
A Joomla 4.2 or later plugin to sort the articles in a category by the value of a custom field.

This is useful when making a category of events where the event date is stored in a Joomla! custom field. Create a menu
item for the category (list or blog view) and set it to order by the value of the event date custom field ascending.
Archive past events. Create another menu item to show only archived articles and set it to sort by the event date custom
field descending. There you go! You now have a quick'n'dirty event calendar using core Joomla features.

I wrote this plugin because I needed it. Also, the use case I had presented back in 2015 in the (literal) round table
discussion regarding Joomla 4 features with regards to custom fields was exactly that: a quick'n'dirty event calendar!
discussion regarding Joomla 4 features with regard to custom fields was exactly that: a quick and dirty event calendar!
It's sad that Joomla decided to add custom fields but not make it possible to sort or filter by them. This plugin gets
the custom fields closer to my original vision of the feature and the possibilities it opens for site integrators.
6 changes: 3 additions & 3 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
A Joomla 3 plugin to sort the articles in a category by the value of a custom field.
A Joomla plugin to sort the articles in a category by the value of a custom field.

**Requirements**
* PHP 7.2 or later; or 8.0
* Joomla 3.9; or 3.10
* PHP 8.0, 8.1, or 8.2
* Joomla 4.2 or later
9 changes: 0 additions & 9 deletions plugins/system/sortbyfield/.htaccess

This file was deleted.

11 changes: 5 additions & 6 deletions plugins/system/sortbyfield/forms/menu.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--~
~ * @project sortbyfield
~ * @license GPLv3
~ * @copyright Copyright (c) 2021 Nicholas K. Dionysopoulos
~ @project sortbyfield
~ @license GPLv3
~ @copyright Copyright (c) 2021-2023 Nicholas K. Dionysopoulos
-->

<form>
<fields name="sortbyfield" addfieldpath="/plugins/system/sortbyfield/fields">
<fields name="sortbyfield" addfieldprefix="Dionysopoulos\Plugin\System\SortByField\Field">
<fieldset name="sortbyfield"
label="PLG_SYSTEM_SORTBYFIELD_FIELDSET_HEAD"

>
<field
name="field"
type="customfield"
type="Joomlafield"
label="PLG_SYSTEM_SORTBYFIELD_FIELD_LABEL"
description="PLG_SYSTEM_SORTBYFIELD_FIELD_DESC"
>
Expand All @@ -28,7 +28,6 @@
<option value="ASC">JGLOBAL_ORDER_ASCENDING</option>
<option value="DESC">JGLOBAL_ORDER_DESCENDING</option>
</field>

</fieldset>
</fields>
</form>
43 changes: 43 additions & 0 deletions plugins/system/sortbyfield/script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @project sortbyfield
* @license GPLv3
* @copyright Copyright (c) 2021-2023 Nicholas K. Dionysopoulos
*/

use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScript;
use Joomla\CMS\Installer\InstallerScriptInterface;

defined('_JEXEC') or die;

return new class extends InstallerScript implements InstallerScriptInterface {
protected $minimumPhp = '8.0';

protected $minimumJoomla = '4.2';

public function preflight($type, $adapter): bool
{
return parent::preflight($type, $adapter);
}

public function install(InstallerAdapter $adapter): bool
{
return true;
}

public function update(InstallerAdapter $adapter): bool
{
return true;
}

public function uninstall(InstallerAdapter $adapter): bool
{
return true;
}

public function postflight(string $type, InstallerAdapter $adapter): bool
{
return true;
}
};
44 changes: 44 additions & 0 deletions plugins/system/sortbyfield/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @project sortbyfield
* @license GPLv3
* @copyright Copyright (c) 2021-2023 Nicholas K. Dionysopoulos
*/

defined('_JEXEC') || die;

use Dionysopoulos\Plugin\System\SortByField\Extension\SortByField;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;

return new class implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*/
public function register(Container $container): void
{
/** @var MVCComponent $component */
$container->set(
PluginInterface::class,
function (Container $container) {
$config = (array) PluginHelper::getPlugin('system', 'sortbyfield');
$subject = $container->get(DispatcherInterface::class);
$plugin = new SortByField($subject, $config);

$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};

20 changes: 9 additions & 11 deletions plugins/system/sortbyfield/sortbyfield.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<!--~
~ * @project sortbyfield
~ * @license GPLv3
~ * @copyright Copyright (c) 2021 Nicholas K. Dionysopoulos
~ @project sortbyfield
~ @license GPLv3
~ @copyright Copyright (c) 2021-2023 Nicholas K. Dionysopoulos
-->

<extension version="3.9.0" type="plugin" group="system" method="upgrade">
<extension type="plugin" group="system" method="upgrade">
<name>PLG_SYSTEM_SORTBYFIELD</name>
<version>1.0.2</version>
<creationDate>2021-03-27</creationDate>
Expand All @@ -15,24 +15,22 @@
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://www.dionysopoulos.me</authorUrl>

<copyright>Copyright (c)2020-2021 Nicholas K. Dionysopoulos</copyright>
<copyright>Copyright (c)2021-2023 Nicholas K. Dionysopoulos</copyright>
<license>GNU GPL v3 or later</license>

<description>PLG_SYSTEM_SORTBYFIELD_XML_DESC</description>
<namespace path="src">Dionysopoulos\Plugin\System\SortByField</namespace>

<files>
<filename plugin="sortbyfield">sortbyfield.php</filename>
<folder>fields</folder>
<folder>forms</folder>
<folder>library</folder>

<filename>.htaccess</filename>
<filename>web.config</filename>
<folder>services</folder>
<folder plugin="sortbyfield">src</folder>
</files>

<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_system_sortbyfield.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_system_sortbyfield.sys.ini</language>
</languages>

<scriptfile>script.php</scriptfile>
</extension>
Loading

0 comments on commit 885a19e

Please sign in to comment.