[TYPO3-german] Problem mit sys_category Auswahl in Frontend Plugin

Matthew Colton mat.colton at web-xs.de
Sat Mar 23 12:29:36 CET 2019


Hi Dieter,
leider funktioniert das so nicht. Ich habe den Aufruf
makeCategorizable() in Overrides verschoben. Die
ext_typoscript_setup.txt kann man sich auch weiterhin nicht sparen,
sonst funktioniert das Mappen in einem Frontend Plugin nicht. Was ich
weglassen konnte war der Kram in der setup.typoscript.

Aber das Ergebnis bleibt identisch, $meinmodel->getCategories liefert
ein leeres ObjectStorage zurück.

Ich kenne leider keine Extension wo in einem Frontend Plugin eine
Kategorie ausgesucht wird, sonst würde ich da mal schauen. Falls jemand
eine kennt freue ich mich auf eine Rückmeldung.

Cheers
Matthew

Web: www.web-xs.de <http://www.web-xs.de>
E-Mail: mat.colton at web-xs.de
Tel: 06621 7941-30
Mobil: 0160 7990125
Ust.-Nr: DE315925085
Am 22.03.19 um 22:32 schrieb _doc:
> Wahrscheinlich fehlt ein Eintrag deiner Tabelle in
> |$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'].|Ich
> hätte mich an die zweite Variante in der Dokumentation gehalten.
> https://docs.typo3.org/typo3cms/CoreApiReference/latest/ApiOverview/Categories/Index.html
> // Add an extra categories selection field to the pages table
> \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
>    'examples',
>    'pages',
>    // Do not use the default field name ("categories") for pages,
> tt_content, sys_file_metadata, which is already used
>    'tx_examples_cats',
>    array(
>       // Set a custom label
>       'label'  => 
> 'LLL:EXT:examples/Resources/Private/Language/locallang.xlf:additional_categories',
>       // This field should not be an exclude-field
>       'exclude'  =>  FALSE,
>       // Override generic configuration, e.g. sort by title rather
> than by sorting
>       'fieldConfiguration'  =>  array(
>          'foreign_table_where'  =>  ' AND
> sys_category.sys_language_uid IN (-1, 0) ORDER BY sys_category.title
> ASC',
>       ),
>       // string (keyword), see TCA reference for details
>       'l10n_mode'  =>  'exclude',
>       // list of keywords, see TCA reference for details
>       'l10n_display'  =>  'hideDiff',
>    )
> ); Dein Typoscript-Model-Geraffel könntest du dann sparen, weil deine
> Tabelle über die MM_Tabelle richtig den Categorien zugeordnet wird.
> Was anderes wäre es natürlich, wenn du in der sys_categories unbedingt
> ein neues Feld brauchst. Das sollte dann aber begründet sein. Das mit
> der Validierung habe ich, einen einfachen Anwendungsfall unterstellt,
> auch nicht verstanden. Ich hätte gemäß der Dokumentation TYPO3
> unterstellt, dass TYPO3 den Eintrag automatisch validiert, wenn die
> TCA-Einträge korrekt sind. Dieter
>
> Am 22.03.2019 um 20:25 schrieb Matthew Colton:
>> Hallo allerseits,
>>
>> ich sitze an einer Erweiterung bei dem die Typo3 Kategorien
>> (sys_category) verwendet werden. Im Backend funktioniert alles prima.
>> Allerding möchte ich auch, dass eine Kategorie in einem Frontend Plugin
>> vom Besucher auswählbar ist. Konkret geht es um eine Vereinsliste.
>>
>> Model und Repository für die Klasse „Category“ habe ich angelegt, diese
>> sind leer und extended einfach nur
>> \TYPO3\CMS\Extbase\Domain\Model\Category und
>> \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository. Die
>> categoryRepository injecte ich im Controller.
>>
>> Weitere Dateien:
>>
>> [ext_tables.php]
>>
>> \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
>>    'Clubs',
>>    'tx_clubs_domain_model_club'
>> );
>>
>>
>> ##########################################
>>
>>
>> [setup.typoscript, Auszug]
>>
>> plugin.tx_clubs_club {
>>
>>     persistence {
>>
>>      storagePid = {$plugin.tx_clubs_club.persistence.storagePid}
>>
>>      classes {
>>
>>        WXS\Clubs\Model\Category {
>>
>>          mapping {
>>
>>            recordType = 0
>>
>>            tableName = sys_category
>>
>>          }
>>
>>        }
>>
>>      }
>>
>>    }
>>
>> }
>>
>>
>> ##########################################
>>
>>
>> [ext_typoscript_setup.txt]
>>
>> config.tx_extbase {
>>
>>    persistence {
>>
>>      classes {
>>
>>        WXS\Clubs\Domain\Model\Category {
>>
>>          mapping {
>>
>>            tableName = sys_category
>>
>>          }
>>
>>        }
>>
>>      }
>>
>>    }
>>
>>    objects {
>>
>>      TYPO3\CMS\Extbase\Domain\Model\Category.className =
>> WXS\Clubs\Domain\Model\Category
>>
>>    }
>>
>> }
>>
>>
>> ##########################################
>>
>>
>> [Vereins-Model (Club), Auszug]
>>
>> /**
>>
>> * @var
>> \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WXS\Clubs\Domain\Model\Category>
>>
>>
>> */
>>
>> protected $categories;
>>
>>
>> function __construct()
>> {
>>      $this->categories = new ObjectStorage();
>> }
>>
>>
>> /**
>>
>> * @param \WXS\Clubs\Domain\Model\Category $category
>>
>> * @return void
>>
>> */
>>
>> public function addCategory(\WXS\Clubs\Domain\Model\Category
>> $category) {
>>
>>      $this->categories->attach($category);
>>
>> }
>>
>>
>> /**
>>
>> * @param \WXS\Clubs\Domain\Model\Category $categoryToRemove The Category
>> to be removed
>>
>> * @return void
>>
>> */
>>
>> public function removeCategory(\WXS\Clubs\Domain\Model\Category
>> $categoryToRemove) {
>>
>>      $this->categories->detach($categoryToRemove);
>>
>> }
>>
>>
>> /**
>>
>> * @return
>> \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WXS\Clubs\Domain\Model\Category>
>>
>> $categories
>>
>> */
>>
>> public function getCategories() {
>>
>>      return $this->categories;
>>
>> }
>>
>>
>> /**
>>
>> * @param
>> \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\WXS\Clubs\Domain\Model\Category>
>>
>> $categories
>>
>> * @return void
>>
>> */
>>
>> public function
>> setCategories(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories){
>>
>>      $this->categories = $categories;
>>
>> }
>>
>>
>> ##########################################
>>
>>
>> Ich lese die verfügbaren Kategorien aus und weise sie den Options einer
>> f:form.select zu:
>>
>>
>> <f:form.select class="form-control" options="{categoryOptions}"
>> property="categories" id="district" optionValueField="uid"
>> optionLabelField="title" prependOptionValue="" prependOptionLabel="Bitte
>> wählen">
>>
>> </f:form.select>
>>
>>
>> Soweit so gut, die Liste erscheint auch korrekt und man kann die
>> gewünschte Kategorie auswählen. Wohlgemerkt, es soll nur eine Kategorie
>> ausgesucht werden, deshalb das Select Element ohne „multiple“.
>>
>>
>> Im Validator versuche ich nun via
>> $value->getCategories()->rewind()->current() auf das Feld zuzugreifen um
>> es zu validieren. Das funktioniert allerdings nicht, der Wert ist
>> einfach NULL. Also habe ich ein var_dump() auf getCategories()
>> losgelassen und erhalte folgende Meldung:
>>
>>
>> ##########################################
>>
>> object(TYPO3\CMS\Extbase\Persistence\ObjectStorage)#1175 (6) {
>>
>> ["warning":"TYPO3\CMS\Extbase\Persistence\ObjectStorage":private]=>
>>
>> string(228) "You should never see this warning. If you do, you probably
>> used PHP array functions like current() on the
>> TYPO3\CMS\Extbase\Persistence\ObjectStorage. To retrieve the first
>> result, you can use the rewind() and current() methods."
>>
>> ["storage":protected]=>
>>
>> array(0) {
>>
>> }
>>
>> ["isModified":protected]=>
>>
>> bool(false)
>>
>> ["addedObjectsPositions":protected]=>
>>
>> array(0) {
>>
>> }
>>
>> ["removedObjectsPositions":protected]=>
>>
>> array(0) {
>>
>> }
>>
>> ["positionCounter":protected]=>
>>
>> int(0)
>>
>> }
>>
>>
>> ##########################################
>>
>> Wenn ich in eine initialize Methode einen vardump mache sehe ich, dass
>> „categories“ ein String mit der korrekten UID der Kategorie ist.
>>
>> Jetzt bin ich überfragt. Was muss ich machen, damit ich auf die Werte
>> des Feldes zugreifen kann. Fehlt da ein Type Converter?
>>
>> Ich bin für jede Hilfe dankbar! :)
>>
>>
>> Cheers,
>>
>> Matthew
>>
>>
>>
>> _______________________________________________
>> TYPO3-german mailing list
>> TYPO3-german at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german
>


More information about the TYPO3-german mailing list