src/FieldHandlers/RelatedFieldTrait.php
protected function _getRelatedProperties(string $tableName, string $data) : array
    {
        $table = TableRegistry::get($tableName);

        $config = (new ModuleConfig(ConfigType::MODULE(), $tableName))->parseToArray();

        $displayField = $table->getDisplayField();
        $displayFieldValue = '';

        try {
            $entity = $this->_getAssociatedRecord($table, $data);

            // get related table's display field value by rendering it through field handler factory
            $value = (new FieldHandlerFactory())->renderValue(
                $table,
                $displayField,
                $entity->get($displayField),
                ['renderAs' => Setting::RENDER_PLAIN_VALUE_RELATED()]
            );
            $displayFieldValue = '' === $value ? 'N/A' : $value;
        } catch (RecordNotFoundException $e) {
            // @todo rethrow the exception
            $entity = null;
        }

        $result = [
            'id' => $data,
            'config' => $config,
            'displayField' => $displayField,
            'entity' => $entity,
            'dispFieldVal' => $displayFieldValue
        ];

        // get plugin and controller names
        list($result['plugin'], $result['controller']) = pluginSplit($table->getAlias());

        return $result;
    }
protected function _getRelatedProperties(string $tableName, string $data) : array
    {
        $table = TableRegistry::get($tableName);

        $config = (new ModuleConfig(ConfigType::MODULE(), $tableName))->parseToArray();

        $displayField = $table->getDisplayField();
        $displayFieldValue = '';

        try {
            $entity = $this->_getAssociatedRecord($table, $data);

            // get related table's display field value by rendering it through field handler factory
            $value = (new FieldHandlerFactory())->renderValue(
                $table,
                $displayField,
                $entity->get($displayField),
                ['renderAs' => Setting::RENDER_PLAIN_VALUE_RELATED()]
            );
            $displayFieldValue = '' === $value ? 'N/A' : $value;
        } catch (RecordNotFoundException $e) {
            // @todo rethrow the exception
            $entity = null;
        }

        $result = [
            'id' => $data,
            'config' => $config,
            'displayField' => $displayField,
            'entity' => $entity,
            'dispFieldVal' => $displayFieldValue
        ];

        // get plugin and controller names
        list($result['plugin'], $result['controller']) = pluginSplit($table->getAlias());

        return $result;
    }
protected function _getRelatedProperties ( string $ tableName , string $ data ) : array { $ table = TableRegistry :: get ( $ tableName ) ; $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ tableName ) ) -> parseToArray ( ) ; $ displayField = $ table -> getDisplayField ( ) ; $ displayFieldValue = '' ; try { $ entity = $ this -> _getAssociatedRecord ( $ table , $ data ) ; // get related table's display field value by rendering it through field handler factory $ value = ( new FieldHandlerFactory ( ) ) -> renderValue ( $ table , $ displayField , $ entity -> get ( $ displayField ) , [ 'renderAs' => Setting :: RENDER_PLAIN_VALUE_RELATED ( ) ] ) ; $ displayFieldValue = '' === $ value ? 'N/A' : $ value ; } catch ( RecordNotFoundException $ e ) { // @todo rethrow the exception $ entity = null ; } $ result = [ 'id' => $ data , 'config' => $ config , 'displayField' => $ displayField , 'entity' => $ entity , 'dispFieldVal' => $ displayFieldValue ] ; // get plugin and controller names list ( $ result [ 'plugin' ] , $ result [ 'controller' ] ) = pluginSplit ( $ table -> getAlias ( ) ) ; return $ result ; }
Get related model's properties.

@param string $tableName Related table name
@param string $data query parameter value
@return mixed[]
Get related model s properties .