public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
    {
        $query->formatResults(function ($results) {
            return $results->map(function ($revision) {
                try {
                    if (isset($revision->data->content_type_id)) {
                        $contentType = TableRegistry::get('Content.ContentTypes')
                            ->find()
                            ->where(['id' => $revision->data->content_type_id])
                            ->first();
                        $revision->data->set('content_type', $contentType);
                    }
                } catch (\Exception $e) {
                    $revision->data->set('content_type', false);
                }

                return $revision;
            });
        });

        return $query;
    }
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
    {
        $query->formatResults(function ($results) {
            return $results->map(function ($revision) {
                try {
                    if (isset($revision->data->content_type_id)) {
                        $contentType = TableRegistry::get('Content.ContentTypes')
                            ->find()
                            ->where(['id' => $revision->data->content_type_id])
                            ->first();
                        $revision->data->set('content_type', $contentType);
                    }
                } catch (\Exception $e) {
                    $revision->data->set('content_type', false);
                }

                return $revision;
            });
        });

        return $query;
    }
public function beforeFind ( Event $ event , Query $ query , ArrayObject $ options , $ primary ) { $ query -> formatResults ( function ( $ results ) { return $ results -> map ( function ( $ revision ) { try { if ( isset ( $ revision -> data -> content_type_id ) ) { $ contentType = TableRegistry :: get ( 'Content.ContentTypes' ) -> find ( ) -> where ( [ 'id' => $ revision -> data -> content_type_id ] ) -> first ( ) ; $ revision -> data -> set ( 'content_type' , $ contentType ) ; } } catch ( \ Exception $ e ) { $ revision -> data -> set ( 'content_type' , false ) ; } return $ revision ; } ) ; } ) ; return $ query ; }
Attaches ContentType information to each content revision.

@param \Cake\Event\Event $event The event that was triggered
@param \Cake\ORM\Query $query The query object
@param \ArrayObject $options Additional options given as an array
@param bool $primary Whether this find is a primary query or not
@return Query
Attaches ContentType information to each content revision .