From e17cc196fa75c62a3dc6df1b570e6c12f24da7c5 Mon Sep 17 00:00:00 2001 From: Ingolf Steinhardt Date: Mon, 8 Jan 2018 09:41:28 +0100 Subject: [PATCH] hotfix add meta data --- composer.json | 2 +- contao/dca/tl_metamodel_attribute.php | 5 ++- .../languages/en/tl_metamodel_attribute.php | 13 +++++- src/MetaModels/Attribute/Alias/Alias.php | 44 +++++++++++++++++-- .../Table/Attribute/Alias/Subscriber.php | 23 ++++++++-- 5 files changed, 75 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 01da551..872581f 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "type": "contao-module", "homepage": "http://now.metamodel.me/", - "license": "LGPL-3.0+", + "license": "LGPL-3.0-or-later", "authors": [ { "name": "Christian Schiffler", diff --git a/contao/dca/tl_metamodel_attribute.php b/contao/dca/tl_metamodel_attribute.php index 3835e0d..04e244f 100644 --- a/contao/dca/tl_metamodel_attribute.php +++ b/contao/dca/tl_metamodel_attribute.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_alias. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,7 +16,7 @@ * @author Andreas Isaak * @author Stefan Heimes * @author Ingolf Steinhardt - * @copyright 2012-2017 The MetaModels team. + * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_alias/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -65,6 +65,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['field_attribute'], 'exclude' => true, 'inputType' => 'select', + 'reference' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values'], 'eval' => array ( 'style' => 'width:600px', diff --git a/contao/languages/en/tl_metamodel_attribute.php b/contao/languages/en/tl_metamodel_attribute.php index 8f39639..ce28be8 100644 --- a/contao/languages/en/tl_metamodel_attribute.php +++ b/contao/languages/en/tl_metamodel_attribute.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_alias. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,7 +16,7 @@ * @author Andreas Isaak * @author Stefan Heimes * @author Ingolf Steinhardt - * @copyright 2012-2017 The MetaModels team. + * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_alias/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -39,3 +39,12 @@ $GLOBALS['TL_LANG']['tl_metamodel_attribute']['force_alias'][1] = 'Check this, if you want the alias to be regenerated whenever any of the dependant fields is changed. Note that ' . 'this will invalidate old urls that are based upon the alias.'; + +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['id'] = 'ID'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['pid'] = 'PID'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['sorting'] = 'Sorting'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['tstamp'] = 'Timestamp'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['vargroup'] = 'Vargroup'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['varbase'] = 'Varbase'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['meta'] = 'Metafields'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['select_values']['attributes'] = 'Attributes'; \ No newline at end of file diff --git a/src/MetaModels/Attribute/Alias/Alias.php b/src/MetaModels/Attribute/Alias/Alias.php index 7fbf1ed..711d3fa 100644 --- a/src/MetaModels/Attribute/Alias/Alias.php +++ b/src/MetaModels/Attribute/Alias/Alias.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_alias. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,7 +18,7 @@ * @author Oliver Hoff * @author Ingolf Steinhardt * @author Sven Baumann - * @copyright 2012-2017 The MetaModels team. + * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_alias/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -142,8 +142,13 @@ private function generateAlias(IItem $objItem) } foreach (deserialize($this->get('alias_fields')) as $strAttribute) { - $arrValues = $objItem->parseAttribute($strAttribute['field_attribute'], 'text', null); - $arrAlias[] = $arrValues['text']; + if ($this->isMetaField($strAttribute['field_attribute'])) { + $strField = $strAttribute['field_attribute']; + $arrAlias[] = $objItem->get($strField); + } else { + $arrValues = $objItem->parseAttribute($strAttribute['field_attribute'], 'text', null); + $arrAlias[] = $arrValues['text']; + } } if ($this->get('alias_postfix')) { @@ -152,4 +157,35 @@ private function generateAlias(IItem $objItem) return implode('-', $arrAlias); } + + /** + * Check if we have a meta field from metamodels. + * + * @param string $strField The selected value. + * + * @return boolean True => Yes we have | False => nope. + */ + protected function isMetaField($strField) + { + $strField = trim($strField); + + if (in_array($strField, $this->getMetaModelsSystemColumns())) { + return true; + } + + return false; + } + + /** + * Returns the global MetaModels System Columns (replacement for super global access). + * + * @return mixed Global MetaModels System Columns + * + * @SuppressWarnings(PHPMD.Superglobals) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) + */ + protected function getMetaModelsSystemColumns() + { + return $GLOBALS['METAMODELS_SYSTEM_COLUMNS']; + } } diff --git a/src/MetaModels/DcGeneral/Events/Table/Attribute/Alias/Subscriber.php b/src/MetaModels/DcGeneral/Events/Table/Attribute/Alias/Subscriber.php index c57470b..fa7e260 100644 --- a/src/MetaModels/DcGeneral/Events/Table/Attribute/Alias/Subscriber.php +++ b/src/MetaModels/DcGeneral/Events/Table/Attribute/Alias/Subscriber.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_alias. * - * (c) 2012-2016 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,8 @@ * @package MetaModels * @subpackage AttributeAlias * @author Christian Schiffler - * @copyright 2012-2016 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_alias/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -101,13 +102,16 @@ public function getOptions(GetOptionsEvent $event) $result = array(); + // Add meta fields. + $result['meta'] = self::getMetaModelsSystemColumns(); + // Fetch all attributes except for the current attribute. foreach ($metaModel->getAttributes() as $attribute) { if ($attribute->get('id') === $model->getId()) { continue; } - $result[$attribute->getColName()] = sprintf( + $result['attributes'][$attribute->getColName()] = sprintf( '%s [%s]', $attribute->getName(), $attribute->get('type') @@ -116,4 +120,17 @@ public function getOptions(GetOptionsEvent $event) $event->setOptions($result); } + + /** + * Returns the global MetaModels System Columns (replacement for super global access). + * + * @return mixed Global MetaModels System Columns + * + * @SuppressWarnings(PHPMD.Superglobals) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) + */ + protected static function getMetaModelsSystemColumns() + { + return $GLOBALS['METAMODELS_SYSTEM_COLUMNS']; + } }