From 9901632f0c21283323f757c9ce1d0582f3fd6c60 Mon Sep 17 00:00:00 2001 From: Thom Vrijmoed Date: Wed, 9 Oct 2019 12:13:01 +0200 Subject: [PATCH] change list item title to optional --- src/controllers/ListsController.php | 21 ++++++++++++++------- src/templates/listitems/_edit.twig | 2 +- src/translations/nl/navie.php | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/controllers/ListsController.php b/src/controllers/ListsController.php index 4f11e17..bfa4fc1 100644 --- a/src/controllers/ListsController.php +++ b/src/controllers/ListsController.php @@ -11,19 +11,19 @@ namespace dutchheight\navie\controllers; -use dutchheight\navie\Navie; -use dutchheight\navie\models\ListModel; -use dutchheight\navie\elements\ListItem; -use dutchheight\navie\assets\cp\Bundle as NavieBundle; - use Craft; use craft\base\Element; use craft\base\Field; use craft\helpers\UrlHelper; -use yii\web\Response; -use yii\web\NotFoundHttpException; +use dutchheight\navie\assets\cp\Bundle as NavieBundle; +use dutchheight\navie\elements\ListItem; +use dutchheight\navie\models\ListModel; +use dutchheight\navie\Navie; + use yii\web\ForbiddenHttpException; +use yii\web\NotFoundHttpException; +use yii\web\Response; /** * @author Dutch Height @@ -527,6 +527,12 @@ private function populateListItemModel(ListItem $listItem) $fieldsLocation = Craft::$app->getRequest()->getParam('fieldsLocation', 'fields'); $listItem->setFieldValuesFromRequest($fieldsLocation); + if (empty($listItem->title) && $listItem->elementId !== null) { + if ($element = Craft::$app->getElements()->getElementById($listItem->elementId)) { + $listItem->title = $element->title; + } + } + // Parent $parentId = $request->getBodyParam('parentId'); if ($parentId !== null) { @@ -651,6 +657,7 @@ private function prepEditListItemVariables(array &$variables) } else { $variables['listItemElement'] = null; $variables['listItem']->url = ''; + $variables['listItem']->elementId = null; } if (!isset($variables['linkType'])) { diff --git a/src/templates/listitems/_edit.twig b/src/templates/listitems/_edit.twig index 599ecf3..6828edc 100644 --- a/src/templates/listitems/_edit.twig +++ b/src/templates/listitems/_edit.twig @@ -83,13 +83,13 @@ {{ forms.textField({ label: "Title"|t('app'), siteId: listItem.siteId, + instructions: "This can be left blank if you just want to use the linked element\'s title."|t('navie'), id: 'title', name: 'title', value: listItem.title, errors: listItem.getErrors('title'), first: true, autofocus: true, - required: true, maxlength: 255 }) }} diff --git a/src/translations/nl/navie.php b/src/translations/nl/navie.php index 4dab929..867e210 100644 --- a/src/translations/nl/navie.php +++ b/src/translations/nl/navie.php @@ -95,4 +95,5 @@ 'Manage items' => 'Lijstitems beheren', 'Load in the same frame as it was clicked' => 'Laad in hetzelfde frame als waarop werd geklikt', 'Load in a new window' => 'Laad in een nieuw venster', + 'This can be left blank if you just want to use the linked element\'s title.' => 'Dit kan blanco worden gelaten indien u de titel van het gelinkte element wilt gebruiken.', ];