Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
administrator/language/en-GB/en-GB.plg_fields_displaylist.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; | ||
; Displaylist language file | ||
; | ||
|
||
PLG_FIELDS_DISPLAYLIST="Fields - Display List" | ||
PLG_FIELDS_DISPLAYLIST_LABEL="Display List (%s)" | ||
PLG_FIELDS_DISPLAYLIST_XML_DESCRIPTION="Plugin to create display list for Joomla custom fields" | ||
PLG_FIELDS_DISPLAYLIST_OUTPUTMODE_LABEL="Output mode" | ||
PLG_DISPLAYLIST_SAMPLE_DESCRIPTION="Set the output mode for the display list" | ||
PLG_FIELDS_DISPLAYLIST_UNORDERED_LIST="Unordered list" | ||
PLG_FIELDS_DISPLAYLIST_ORDERED_LIST="Ordered list" | ||
PLG_FIELDS_DISPLAYLIST_PARAMS_LIST_NAME_LABEL="List Name" | ||
PLG_FIELDS_DISPLAYLIST_PARAMS_LIST_NAME_DESC="" | ||
PLG_FIELDS_DISPLAYLISTS_PARAMS_OPTIONS_LABEL="List Items" | ||
PLG_FIELDS_DISPLAYLISTS_LIST_ITEM_LABEL="List item" |
13 changes: 13 additions & 0 deletions
13
administrator/language/en-GB/en-GB.plg_fields_displaylist.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; | ||
; Displaylist language file | ||
; | ||
|
||
PLG_FIELDS_DISPLAYLIST="Fields - Display List" | ||
PLG_FIELDS_DISPLAYLIST_LABEL="Display List (%s)" | ||
PLG_FIELDS_DISPLAYLIST_XML_DESCRIPTION="Plugin to create display list for Joomla custom fields" | ||
PLG_FIELDS_DISPLAYLIST_OUTPUTMODE_LABEL="Output mode" | ||
PLG_DISPLAYLIST_SAMPLE_DESCRIPTION="Set the output mode for the display list" | ||
PLG_FIELDS_DISPLAYLIST_UNORDERED_LIST="Unordered list" | ||
PLG_FIELDS_DISPLAYLIST_ORDERED_LIST="Ordered list" | ||
PLG_FIELDS_DISPLAYLIST_PARAMS_LIST_NAME_LABEL="List Name" | ||
PLG_FIELDS_DISPLAYLISTS_PARAMS_OPTIONS_LABEL="Display List Values" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Plugin | ||
* @subpackage Fields.DisplayList | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
use Joomla\CMS\MVC\Model\BaseDatabaseModel; | ||
use Joomla\CMS\MVC\Model\BaseModel; | ||
|
||
defined('_JEXEC') or die; | ||
|
||
JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); | ||
|
||
/** | ||
* Display list plugin. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class PlgFieldsDisplayList extends FieldsPlugin | ||
{ | ||
/** | ||
* Transforms the field into a DOM XML element and appends it as a child on the given parent. | ||
* | ||
* @param stdClass $field The field. | ||
* @param DOMElement $parent The field node parent. | ||
* @param JForm $form The form. | ||
* | ||
* @return DOMElement | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form) | ||
{ | ||
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); | ||
|
||
if (!$fieldNode) | ||
{ | ||
return $fieldNode; | ||
} | ||
|
||
$fieldNode->setAttribute('type', 'subform'); | ||
$fieldNode->setAttribute('multiple', 'true'); | ||
$fieldNode->setAttribute('formsource', '/plugins/fields/displaylist/params/displaylist.xml'); | ||
$fieldNode->setAttribute('layout', 'joomla.form.field.subform.repeatable-table'); | ||
|
||
// Return the node | ||
return $fieldNode; | ||
} | ||
|
||
/** | ||
* The save event. | ||
* | ||
* @param string $context The context | ||
* @param JTable $item The article data | ||
* @param boolean $isNew Is new item | ||
* @param array $data The validated data | ||
* | ||
* @return boolean | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function onContentAfterSave($context, $item, $isNew, $data = array()) | ||
{ | ||
// Create correct context for category | ||
if ($context == 'com_categories.category') | ||
{ | ||
$context = $item->get('extension') . '.categories'; | ||
|
||
// Set the catid on the category to get only the fields which belong to this category | ||
$item->set('catid', $item->get('id')); | ||
} | ||
|
||
// Check the context | ||
$parts = FieldsHelper::extract($context, $item); | ||
|
||
if (!$parts) | ||
{ | ||
return true; | ||
} | ||
|
||
// Compile the right context for the fields | ||
$context = $parts[0] . '.' . $parts[1]; | ||
|
||
// Loading the fields | ||
$fields = FieldsHelper::getFields($context, $item); | ||
|
||
if (!$fields) | ||
{ | ||
return true; | ||
} | ||
|
||
// Get the fields data | ||
$fieldsData = !empty($data['com_fields']) ? $data['com_fields'] : array(); | ||
|
||
// Loading the model | ||
/** @var FieldsModelField $model */ | ||
$model = BaseDatabaseModel::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); | ||
|
||
// Loop over the fields | ||
foreach ($fields as $field) | ||
{ | ||
// Find the field of this type displaylist | ||
if ($field->type === $this->_name) | ||
{ | ||
// Determine the value if it is available from the data | ||
$value = key_exists($field->name, $fieldsData) ? $fieldsData[$field->name] : null; | ||
|
||
// Setting the value for the field and the item | ||
$value = json_encode($value); | ||
|
||
// Setting the value for the field and the item | ||
$model->setFieldValue($field->id, $item->get('id'), $value); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<extension type="plugin" version="3.8.0" group="fields" method="upgrade"> | ||
<name>plg_fields_displaylist</name> | ||
<author>Joomla! Project</author> | ||
<creationDate>April 2018</creationDate> | ||
<copyright>Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.</copyright> | ||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> | ||
<authorEmail>admin@joomla.org</authorEmail> | ||
<authorUrl>www.joomla.org</authorUrl> | ||
<version>__DEPLOY_VERSION__</version> | ||
<description>PLG_FIELDS_DISPLAYLIST_XML_DESCRIPTION</description> | ||
<files> | ||
<filename plugin="displaylist">displaylist.php</filename> | ||
<folder>params</folder> | ||
<folder>tmpl</folder> | ||
</files> | ||
<languages folder="language"> | ||
<language tag="en-GB">en-GB/en-GB.plg_fields_displaylist.ini</language> | ||
<language tag="en-GB">en-GB/en-GB.plg_fields_displaylist.sys.ini</language> | ||
</languages> | ||
</extension> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<form> | ||
<fields> | ||
<fieldset> | ||
<field | ||
name="options" | ||
type="text" | ||
icon="list" | ||
label="PLG_FIELDS_DISPLAYLIST_PARAMS_LIST_NAME_LABEL" | ||
description="PLG_FIELDS_DISPLAYLIST_PARAMS_LIST_NAME_DESC" | ||
multiple="true" | ||
> | ||
</field> | ||
</fieldset> | ||
</fields> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Plugin | ||
* @subpackage Fields.DisplayList | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
$fieldValue = $field->value; | ||
|
||
if ($fieldValue === '') | ||
{ | ||
return; | ||
} | ||
|
||
// Get the values | ||
$fieldValues = json_decode($fieldValue, true); | ||
|
||
if (empty($fieldValues)) | ||
{ | ||
return; | ||
} | ||
|
||
$html = '<ul>'; | ||
|
||
foreach ($fieldValues as $value) | ||
{ | ||
$html .= '<li>' . $value['options'] . '</li>'; | ||
} | ||
|
||
$html .= '</ul>'; | ||
|
||
echo $html; |