src/Generator/Analyzer/Steps/AnalyzeSluggableInteractive.php
protected function applyOverrideForSluggable(array $model)
    {
        if ( ! array_key_exists($model['module'], $this->overrides)) {
            return false;
        }

        $override = $this->overrides[ $model['module'] ];

        $analysis = [
            'translated'              => false,
            'slug_column'             => null,
            'slug_sources_normal'     => [],
            'slug_sources_translated' => [],
        ];

        // set the source attribute (determine whether it is available and/or translatable)

        if ( ! array_key_exists('source', $override)) {
            $this->context->log(
                "Invalid slugs override configuration for model #{$model['module']}. No source.",
                Generator::LOG_LEVEL_ERROR
            );
            return false;
        }

        if (in_array($override['source'], $model['normal_attributes'])) {

            $analysis['slug_sources_normal'] = [ $override['source'] ];

        } elseif (in_array($override['source'], $model['translated_attributes'])) {

            $analysis['slug_sources_translated'] = [ $override['source'] ];

        } else {
            // couldn't find the attribute
            $this->context->log(
                "Invalid slugs override configuration for model #{$model['module']}. "
                . "Source attribute '{$override['source']}' does not exist.",
                Generator::LOG_LEVEL_ERROR
            );
            return false;
        }

        // if provided, check and set the slug target attribute (on the model itself)
        if (isset($override['slug'])) {

            if ($override['slug'] == $override['source']) {
                $this->context->log(
                    "Invalid slugs override configuration for model #{$model['module']}. "
                    . "Slug attribute '{$override['slug']}' is same as source attribute.",
                    Generator::LOG_LEVEL_ERROR
                );
                return false;
            }

            if (in_array($override['slug'], $model['normal_attributes'])) {

                $analysis['translated'] = false;

            } elseif (in_array($override['slug'], $model['translated_attributes'])) {

                $analysis['translated'] = true;

            } else {
                // couldn't find the attribute
                $this->context->log(
                    "Invalid slugs override configuration for model #{$model['module']}. "
                    . "Slug attribute '{$override['slug']}' does not exist.",
                    Generator::LOG_LEVEL_ERROR
                );
                return false;
            }

            $analysis['slug_column'] = $override['slug'];

            // if source is translated, slug must be, and vice versa!
            if (    $analysis['translated']   && count($analysis['slug_sources_normal'])
                ||  ! $analysis['translated'] && count($analysis['slug_sources_translated'])
            ) {
                $this->context->log(
                    "Invalid slugs override configuration for model #{$model['module']}. "
                    . "Either Slug and Source attribute must be translated, or neither.",
                    Generator::LOG_LEVEL_ERROR
                );
                return false;
            }
        }

        // ensure that translated is set if source is translated
        $analysis['translated'] = (count($analysis['slug_sources_translated']) > 0);

        return $analysis;
    }
protected function applyOverrideForSluggable(array $model)
    {
        if ( ! array_key_exists($model['module'], $this->overrides)) {
            return false;
        }

        $override = $this->overrides[ $model['module'] ];

        $analysis = [
            'translated'              => false,
            'slug_column'             => null,
            'slug_sources_normal'     => [],
            'slug_sources_translated' => [],
        ];

        // set the source attribute (determine whether it is available and/or translatable)

        if ( ! array_key_exists('source', $override)) {
            $this->context->log(
                "Invalid slugs override configuration for model #{$model['module']}. No source.",
                Generator::LOG_LEVEL_ERROR
            );
            return false;
        }

        if (in_array($override['source'], $model['normal_attributes'])) {

            $analysis['slug_sources_normal'] = [ $override['source'] ];

        } elseif (in_array($override['source'], $model['translated_attributes'])) {

            $analysis['slug_sources_translated'] = [ $override['source'] ];

        } else {
            // couldn't find the attribute
            $this->context->log(
                "Invalid slugs override configuration for model #{$model['module']}. "
                . "Source attribute '{$override['source']}' does not exist.",
                Generator::LOG_LEVEL_ERROR
            );
            return false;
        }

        // if provided, check and set the slug target attribute (on the model itself)
        if (isset($override['slug'])) {

            if ($override['slug'] == $override['source']) {
                $this->context->log(
                    "Invalid slugs override configuration for model #{$model['module']}. "
                    . "Slug attribute '{$override['slug']}' is same as source attribute.",
                    Generator::LOG_LEVEL_ERROR
                );
                return false;
            }

            if (in_array($override['slug'], $model['normal_attributes'])) {

                $analysis['translated'] = false;

            } elseif (in_array($override['slug'], $model['translated_attributes'])) {

                $analysis['translated'] = true;

            } else {
                // couldn't find the attribute
                $this->context->log(
                    "Invalid slugs override configuration for model #{$model['module']}. "
                    . "Slug attribute '{$override['slug']}' does not exist.",
                    Generator::LOG_LEVEL_ERROR
                );
                return false;
            }

            $analysis['slug_column'] = $override['slug'];

            // if source is translated, slug must be, and vice versa!
            if (    $analysis['translated']   && count($analysis['slug_sources_normal'])
                ||  ! $analysis['translated'] && count($analysis['slug_sources_translated'])
            ) {
                $this->context->log(
                    "Invalid slugs override configuration for model #{$model['module']}. "
                    . "Either Slug and Source attribute must be translated, or neither.",
                    Generator::LOG_LEVEL_ERROR
                );
                return false;
            }
        }

        // ensure that translated is set if source is translated
        $analysis['translated'] = (count($analysis['slug_sources_translated']) > 0);

        return $analysis;
    }
protected function applyOverrideForSluggable ( array $ model ) { if ( ! array_key_exists ( $ model [ 'module' ] , $ this -> overrides ) ) { return false ; } $ override = $ this -> overrides [ $ model [ 'module' ] ] ; $ analysis = [ 'translated' => false , 'slug_column' => null , 'slug_sources_normal' => [ ] , 'slug_sources_translated' => [ ] , ] ; // set the source attribute (determine whether it is available and/or translatable) if ( ! array_key_exists ( 'source' , $ override ) ) { $ this -> context -> log ( "Invalid slugs override configuration for model #{$model['module']}. No source." , Generator :: LOG_LEVEL_ERROR ) ; return false ; } if ( in_array ( $ override [ 'source' ] , $ model [ 'normal_attributes' ] ) ) { $ analysis [ 'slug_sources_normal' ] = [ $ override [ 'source' ] ] ; } elseif ( in_array ( $ override [ 'source' ] , $ model [ 'translated_attributes' ] ) ) { $ analysis [ 'slug_sources_translated' ] = [ $ override [ 'source' ] ] ; } else { // couldn't find the attribute $ this -> context -> log ( "Invalid slugs override configuration for model #{$model['module']}. " . "Source attribute '{$override['source']}' does not exist." , Generator :: LOG_LEVEL_ERROR ) ; return false ; } // if provided, check and set the slug target attribute (on the model itself) if ( isset ( $ override [ 'slug' ] ) ) { if ( $ override [ 'slug' ] == $ override [ 'source' ] ) { $ this -> context -> log ( "Invalid slugs override configuration for model #{$model['module']}. " . "Slug attribute '{$override['slug']}' is same as source attribute." , Generator :: LOG_LEVEL_ERROR ) ; return false ; } if ( in_array ( $ override [ 'slug' ] , $ model [ 'normal_attributes' ] ) ) { $ analysis [ 'translated' ] = false ; } elseif ( in_array ( $ override [ 'slug' ] , $ model [ 'translated_attributes' ] ) ) { $ analysis [ 'translated' ] = true ; } else { // couldn't find the attribute $ this -> context -> log ( "Invalid slugs override configuration for model #{$model['module']}. " . "Slug attribute '{$override['slug']}' does not exist." , Generator :: LOG_LEVEL_ERROR ) ; return false ; } $ analysis [ 'slug_column' ] = $ override [ 'slug' ] ; // if source is translated, slug must be, and vice versa! if ( $ analysis [ 'translated' ] && count ( $ analysis [ 'slug_sources_normal' ] ) || ! $ analysis [ 'translated' ] && count ( $ analysis [ 'slug_sources_translated' ] ) ) { $ this -> context -> log ( "Invalid slugs override configuration for model #{$model['module']}. " . "Either Slug and Source attribute must be translated, or neither." , Generator :: LOG_LEVEL_ERROR ) ; return false ; } } // ensure that translated is set if source is translated $ analysis [ 'translated' ] = ( count ( $ analysis [ 'slug_sources_translated' ] ) > 0 ) ; return $ analysis ; }
Returns overridden analysis result for model
after checking it against the model's data

@param array $model
@return array|false
Returns overridden analysis result for model after checking it against the model s data