src/Generator/Writer/Model/Steps/StubReplaceRelationData.php
protected function getRelationMethodSection(array $relationships, $type = CmsModel::RELATION_TYPE_MODEL)
    {
        $replace = '';

        $relatedClassName = $this->context->getModelNamespaceForSpecialModel($type);

        foreach ($relationships as $name => $relationship) {

            $relationParameters       = '';
            $relationMethodParameters = '';

            if ($relationKey = array_get($relationship, 'key')) {
                $relationParameters = ", '{$relationKey}'";
            }

            if (    array_get($relationship, 'translated')
                &&  $type !== CmsModel::RELATION_TYPE_MODEL
                &&  config('pxlcms.generator.models.allow_locale_override_on_translated_model_relation')
            ) {
                $relationMethodParameters = '$locale = null';

                // skip parameters not entered, pass on the optional locale key
                $relationParameters = (substr_count($relationParameters, ',') ? null : ', null')
                                    . ', null'
                                    . ', $locale';
            }

            $replace .= $this->tab() . "public function {$name}({$relationMethodParameters})\n"
                      . $this->tab() . "{\n"
                      . $this->tab(2) . "return \$this->{$relationship['type']}({$relatedClassName}::class"
                      . $relationParameters
                      . ");\n"
                      . $this->tab() . "}\n"
                      . "\n";


            if ($type == CmsModel::RELATION_TYPE_IMAGE) {
                // since images require special attention for resize enrichment,
                // add an accessor method that will take care of it (through some magic)
                $replace .= $this->tab() . "public function get" . studly_case($name) . "Attribute()\n"
                          . $this->tab() . "{\n"
                          . $this->tab(2) . "return \$this->getImagesWithResizes();\n"
                          . $this->tab() . "}\n"
                          . "\n";
            }

        }

        return $replace;
    }
protected function getRelationMethodSection(array $relationships, $type = CmsModel::RELATION_TYPE_MODEL)
    {
        $replace = '';

        $relatedClassName = $this->context->getModelNamespaceForSpecialModel($type);

        foreach ($relationships as $name => $relationship) {

            $relationParameters       = '';
            $relationMethodParameters = '';

            if ($relationKey = array_get($relationship, 'key')) {
                $relationParameters = ", '{$relationKey}'";
            }

            if (    array_get($relationship, 'translated')
                &&  $type !== CmsModel::RELATION_TYPE_MODEL
                &&  config('pxlcms.generator.models.allow_locale_override_on_translated_model_relation')
            ) {
                $relationMethodParameters = '$locale = null';

                // skip parameters not entered, pass on the optional locale key
                $relationParameters = (substr_count($relationParameters, ',') ? null : ', null')
                                    . ', null'
                                    . ', $locale';
            }

            $replace .= $this->tab() . "public function {$name}({$relationMethodParameters})\n"
                      . $this->tab() . "{\n"
                      . $this->tab(2) . "return \$this->{$relationship['type']}({$relatedClassName}::class"
                      . $relationParameters
                      . ");\n"
                      . $this->tab() . "}\n"
                      . "\n";


            if ($type == CmsModel::RELATION_TYPE_IMAGE) {
                // since images require special attention for resize enrichment,
                // add an accessor method that will take care of it (through some magic)
                $replace .= $this->tab() . "public function get" . studly_case($name) . "Attribute()\n"
                          . $this->tab() . "{\n"
                          . $this->tab(2) . "return \$this->getImagesWithResizes();\n"
                          . $this->tab() . "}\n"
                          . "\n";
            }

        }

        return $replace;
    }
protected function getRelationMethodSection ( array $ relationships , $ type = CmsModel :: RELATION_TYPE_MODEL ) { $ replace = '' ; $ relatedClassName = $ this -> context -> getModelNamespaceForSpecialModel ( $ type ) ; foreach ( $ relationships as $ name => $ relationship ) { $ relationParameters = '' ; $ relationMethodParameters = '' ; if ( $ relationKey = array_get ( $ relationship , 'key' ) ) { $ relationParameters = ", '{$relationKey}'" ; } if ( array_get ( $ relationship , 'translated' ) && $ type !== CmsModel :: RELATION_TYPE_MODEL && config ( 'pxlcms.generator.models.allow_locale_override_on_translated_model_relation' ) ) { $ relationMethodParameters = '$locale = null' ; // skip parameters not entered, pass on the optional locale key $ relationParameters = ( substr_count ( $ relationParameters , ',' ) ? null : ', null' ) . ', null' . ', $locale' ; } $ replace .= $ this -> tab ( ) . "public function {$name}({$relationMethodParameters})\n" . $ this -> tab ( ) . "{\n" . $ this -> tab ( 2 ) . "return \$this->{$relationship['type']}({$relatedClassName}::class" . $ relationParameters . ");\n" . $ this -> tab ( ) . "}\n" . "\n" ; if ( $ type == CmsModel :: RELATION_TYPE_IMAGE ) { // since images require special attention for resize enrichment, // add an accessor method that will take care of it (through some magic) $ replace .= $ this -> tab ( ) . "public function get" . studly_case ( $ name ) . "Attribute()\n" . $ this -> tab ( ) . "{\n" . $ this -> tab ( 2 ) . "return \$this->getImagesWithResizes();\n" . $ this -> tab ( ) . "}\n" . "\n" ; } } return $ replace ; }
Returns stub section for relation method

@param array    $relationships
@param int|null $type            CmsModel::RELATION_TYPE_...
@return string
Returns stub section for relation method