Skip to content

Commit

Permalink
Merge pull request #2 from dutchheight/feature-title-optional
Browse files Browse the repository at this point in the history
changed list item title to optional
  • Loading branch information
freimutt authored Oct 9, 2019
2 parents a79e252 + 9901632 commit 57f0978
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/controllers/ListsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -651,6 +657,7 @@ private function prepEditListItemVariables(array &$variables)
} else {
$variables['listItemElement'] = null;
$variables['listItem']->url = '';
$variables['listItem']->elementId = null;
}

if (!isset($variables['linkType'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/listitems/_edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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
}) }}

Expand Down
1 change: 1 addition & 0 deletions src/translations/nl/navie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
];

0 comments on commit 57f0978

Please sign in to comment.