Hallo liebe Entwickler,
ich möchte gern Redakteuren beim Anlegen/Bearbeiten von Artikeln nur die Bereiche zur Auswahl anbieten, die auch im Layout der Seite für Artikel vorgesehen sind. Für die Historie bzw. weitere Argumente seht bitte diesen Forum-Thread und dies Ticket.
Also habe ich mich auf den Hosenboden gesetzt und eine Erweiterung zz_betterdisplayin geschrieben (siehe auch unten), die das tut. Für mich recht aufwändig/zeitintensiv, weil ich als Neuling ja ziemlich viel forschen musste. Aber das Ergebnis ist dann doch recht simpel/überschaubar und tut es für mich (TL 2.7.5 mit wenigen anderen Erweiterungen).
Für Artikel mit korrekter Platzierung sieht das dann etwa so aus:
Falls der Artikel bereits falsch platziert ist, dann sieht das so aus:
Eine falsche Platzierung kann mehrere Gründe haben:
- die Erweiterung war noch nicht installiert
- ein Artikel wurde aus einer Seite mit Layout X in eine Seite mit Layout Y verschoben
- das Layout selbst wurde verändert
Was mir Sorgen macht ist Leos Antwort
You are not the first one to request this and it is still not possible I'm afraid.
sprich, ich befürchte, dass ich etwas Entscheidendes übersehen habe.
Ich fände es toll, wenn Ihr einmal den Code besichtigt und mir Rückkopplung gebt, was ich wohl übersehen haben mag. Einige Schwächen kenne ich schon jetzt:
- die spezielle Markierung von falsch platzierten Artikeln wird erst sichtbar, wenn man den Artikel selbst bearbeitet. In allen Listenanzeigen usw. wird nicht darauf hingewiesen.
- es wird Erweiterungen geben, die selbst auch an der Platzierung drehen (etwa 'boxes').
Falls Ihr den Code eines Tests würdig befindet, würde ich mich natürlich sehr freuen, wenn Ihr ihn erprobt und mir Hinweise gebt, wo er nicht funktioniert bzw. mit welchen Erweiterungen er nicht zusammen spielt.
Die Erweiterung ändert NICHTS an der Datenbank, sondern nur die Anzeige im Backend-Artikel-Formular ... falls sie also nicht funktioniert, kann man sie entweder einfach abschalten (Einstellungen) oder schlicht vom System löschen und alles sollte unverändert sein.
Hier der wesentliche Code:
PHP-Code:
/* ..../dca/tl_article.php */
// Replace 'options' with 'options_callback'.
unset($GLOBALS['TL_DCA']['tl_article']['fields']['inColumn']['options']);
$GLOBALS['TL_DCA']['tl_article']['fields']['inColumn']['options_callback'] =
array('BetterDisplayIn', 'getAvailablePageSections');
PHP-Code:
/**
* ....
* The code here is, intentionally, very verbose, spread out over several
* lines and has intermediate variables one normally wouldn't need. This is so,
* ....
*/
class BetterDisplayIn extends Backend {
/**
* Constructor (is it needed as public method?)
*/
public function __construct() {
parent::__construct();
}
/**
* Returns the page sections available for a page as of it's assigned layout.
*
* @return array
*/
public function getAvailablePageSections() {
// Get all page sections the same way TYPOlight normally does.
$resultSections = $this->getPageSections();
// Get the article id worked on.
$this->import('Input');
$articleId = $this->Input->get('id');
// Get the page object for the article at hand,
// so that we later can know the page layout.
$this->import('Database');
$query = '
SELECT pid, inColumn
FROM tl_article
WHERE id = ?
';
$objResult = $this->Database
->prepare($query)
->limit(1)
->execute($articleId);
if ($objResult->numRows < 1) {
return $resultSections;
}
// Remember the current column, in case it is not in layout of the page.
// This can e.g. happen, when the article was moved from a page with one
// layout to a page with a different layout.
$inColumn = $objResult->inColumn;
// Get the page object by calling a TL method.
// This is essential, because not every page has it's own layout,
// but inherits it from a parent page.
$objPage = $this->getPageDetails($objResult->pid);
// Get the modules array from the pages layout.
$query = '
SELECT modules
FROM tl_layout
WHERE id = ?
';
$objLayout = $this->Database
->prepare($query)
->limit(1)
->execute($objPage->layout);
$modules = deserialize($objLayout->modules);
// Get the allowed sections for articles from the modules array.
$allowedSections = array();
foreach ($modules as $v) {
if ($v['mod'] == 0) {
// Article module has id 0 (not in DB)
$allowedSections[] = $v['col'];
}
}
$resultSections = $allowedSections;
// Handle the case, that the article is not in the allowed sections.
// Then add a note to the label of the select box.
if (! in_array($inColumn, $allowedSections)) {
$allowedSections[] = $inColumn;
// Must change the result array from numeric to assoc to add the note.
$resultSections = array();
foreach ($allowedSections as $section) {
$resultSections[$section] = (
isset($GLOBALS['TL_LANG']['tl_article'][$section])
? $GLOBALS['TL_LANG']['tl_article'][$section]
: $section
);
if ($section == $inColumn) {
// Add the note.
$resultSections[$section] .= $GLOBALS['TL_LANG']['MSC']['section_not_in_layout'];
}
}
}
return $resultSections;
}
}
Zum Testen siehe Link unten, gepackt wie für das Repository erforderlich, aber noch ohne 'package.xml'.
Danke für Eure Zeit,
Liebe Grüße, Georg
Lesezeichen