[TYPO3-mvc] hidden records seem to be unworkable with extbase + is extbase bloated ?

Alban Cousinié lists at mind2machine.com
Tue Apr 26 19:01:08 CEST 2011


Hi everybody,

 

I've been working on switching the hidden of records for the last 24 hours,
making progress slowly but surely. However I have reached a point where I am
stuck, and this is because I assume the extbase framework seems to be just
unable to deal with hidden records : it seems to be unable to load them
before even calling the action handler, and it fails on any action targeted
to a hidden with the following error :

 

#1251730701: The value must be of type
"Tx_M2mHumanRessources_Domain_Model_JobOffer", but was of type "NULL". 

Tx_Extbase_MVC_Exception_InvalidArgumentValue thrown in file
/home/vulcania/typo3_src-4.5.2/typo3/sysext/extbase/Classes/MVC/Controller/A
rgument.php in line 389.

 

 

This is what I have done (more human readable thoughts at the bottom if you
don't want to parse all this code): 

 

In my domain, added the hidden property handling :

 

                /**

                 * Record visibility

                 *

                 * @var integer $hidden

                 */

                protected $hidden;

 

                /**

                 * Sets the visibility

                 *

                 * @param integer $hidden

                 * @return void

                 */

                public function setHidden($hidden) {

                               $this->hidden = $hidden;

                }

 

                /**

                 * Returns the visibility

                 *

                 * @return integer

                 */

                public function getHidden() {

                               return $this->hidden;

                }

 

In my controller, added the hide / unhide actions :

 

                /**

                 * Hides an existing JobOffer

                 *

                 * @param Tx_M2mHumanRessources_Domain_Model_JobOffer
$jobOffer the JobOffer to be hidden

                 * @return void

                 */

                public function
hideAction(Tx_M2mHumanRessources_Domain_Model_JobOffer $jobOffer) {

                               $jobOffer->setHidden(1);

                               $this->jobOfferRepository->update($jobOffer);

                               $this->flashMessageContainer->add('Your
JobOffer was hidden.');

                               $this->redirect('list');

                }

                

                /**

                 * Unhides an existing JobOffer

                 *

                 * @param Tx_M2mHumanRessources_Domain_Model_JobOffer
$jobOffer the JobOffer to be unhidden

                 * @return void

                 */

                public function
unhideAction(Tx_M2mHumanRessources_Domain_Model_JobOffer $jobOffer) {

                               $jobOffer->setHidden(0);

                               $this->jobOfferRepository->update($jobOffer);

                               $this->flashMessageContainer->add('Your
JobOffer was unhidden.');

                               $this->redirect('list');

                }

 

 

In my ext_localconf.php, added the hide / unhide actions :

 

Tx_Extbase_Utility_Extension::configurePlugin(

                $_EXTKEY,

                'Pi1',

                array(

                               'JobOffer' => 'list, show, new, create, edit,
update, delete, hide, unhide',

                ),

                array(

                               'JobOffer' => 'create, update, delete, hide,
unhide',

                )

);

 

In my ext_tables.php added the hide / unhide actions to my module (they
would not work otherwise)

 

/**

                * Registers a Backend Module

                */

                Tx_Extbase_Utility_Extension::registerModule(

                               $_EXTKEY,

                               'web',   // Make module a submodule of 'web'

                               'mod1', // Submodule key

                               '',
// Position

                               array(

                                               'JobOffer' => 'list, show,
new, create, edit, update, delete, hide, unhide',

                               ),

                               array(

                                               'access' => 'user,group',

                                               'icon'   => 'EXT:' . $_EXTKEY
. '/ext_icon.gif',

                                               'labels' => 'LLL:EXT:' .
$_EXTKEY . '/Resources/Private/Language/locallang_mod1.xml',

                               )

                );

 

Then finally In my repository, I had to overload createQuery() using
setRespectEnableFields(FALSE) as already stated on this list

 

                /**

                 * * @var boolean

                 */

                private $enableHiddenFields = true; //enable hidden fields
by default

 

                /** 

                 * Returns a query for objects of this repository * 

                 * @return Tx_Extbase_Persistence_QueryInterface * @api

                 */

                public function createQuery() {

                               $query =
$this->queryFactory->create($this->objectType);

                               

                               if ($this->enableHiddenFields) {

 
$query->getQuerySettings()->setRespectEnableFields(FALSE);

 
$query->matching($query->equals('deleted', 0));

 
//$query->matching($query->greaterThanOrEqual('hidden', "0")); //make sure
hidden >= 0 is always retreived

                               }

                               return $query;

                }

 

                public function setEnableHiddenFields($value) {

                               $this->enableHiddenFields = $value;

                }

 

                public function getEnableHiddenFields($value) {

                               return $enableHiddenFields;

                }

 

 

All this code for requesting a record with a miserable flag that would
require a couple of minutes using a simple SQL request. I feel very
depressed.

 

Now here are a few thought that come to my mind :

 

- First I don't understand why the enable fields are not basically handled
in base Domains classes since they are the earth of Typo3 database records
mecanism. But I can hear there can be types of records no stored in the
database which do not require any enable fields. So why not, but also why
not have them inherited by default (this would add a lot of productivity)
and not use them if you don't need them ...

 

- Second I beleive Extbase / Flow3 should return any records found and let
the programmer filter them according to his needs. Pre-filtering records
like done actually leads to unproductive and complex situations where you
have to circumvent filtering mecanism to retreive your objects instead of
just specifying what to request.

 

- Third, I have been working with extbase for about 2 weeks now with very
little advancement. I am used to be searching and experimenting things when
learning a new programming language and so I make abstraction of that when
stating this, but I have the feeling that there is so much source code that
the framework has reached a point where its complexity overrides the
simplicity it tries to bring. 

I have now understood the most important aspects of programming with extbase
/ flow3 and in many aspects they are very smart and I have a lot of respect
for the work done by the conceptors on it and the time they dedicated to it.

I would say fluid is very cool because viewhelpers definately succeed at
hidding the complexity. You can create huge logic that you can simply hide
behind a small tag: it is awesome. 

But extbase, while it allows to create simple Object classes requires in the
same time so many classes and directories where the code is split that it
becomes very complex to deal with all those files and inheritance. In my
extension I have 6 Domains, 3 Modules, 1 plugin. And I have 194 files to
deal with that : 194 FILES !!! And extbase itself is made of 362 files while
not being able to generate a TCA style backend form and only providing a
fe_user, fe_group and configurationManager objects to deal with Typo3 !

Typo3 has always been very good at making simple things using very complex
code with thousand of lines. I had hopes extbase / flow3 would sweep that
and bring a new fresh simplicity. But from what I have experienced with it
so far, the target of simplicity has been missed because the thousands lines
of code have been converted into hundreds of files. Too bad.

 

Regards,

 

Alban



More information about the TYPO3-project-typo3v4mvc mailing list