idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
52,200
protected function getRelationMappedMorphClass ( $ type ) { $ map = Relation :: morphMap ( ) ; if ( empty ( $ map ) ) { return $ type ; } return array_get ( $ map , $ type , ltrim ( $ type , '\\' ) ) ; }
Returns morph relation class string for a morph relation type or type if already a class .
52,201
public function interpret ( $ information ) { $ this -> raw = $ information ; $ this -> interpretReferenceData ( ) -> interpretListData ( ) -> interpretFormData ( ) -> interpretShowData ( ) -> interpretExportData ( ) ; return $ this -> createInformationInstance ( ) ; }
Interprets raw CMS model information as a model information object .
52,202
protected function normalizeScopeArray ( array $ scopes , $ parentKey = 'list.scopes' ) { $ scopes = $ this -> normalizeStandardArrayProperty ( $ scopes , 'strategy' , ModelScopeData :: class , $ parentKey ) ; foreach ( $ scopes as $ key => & $ value ) { if ( ! $ value [ 'method' ] && ! $ value [ 'strategy' ] ) { $ value [ 'method' ] = $ key ; } } unset ( $ value ) ; return $ scopes ; }
Normalizes an array with scope data .
52,203
protected function normalizeStandardArrayProperty ( array $ source , $ standardProperty , $ objectClass = null , $ parentKey = null ) { $ normalized = [ ] ; foreach ( $ source as $ key => $ value ) { if ( is_numeric ( $ key ) && ! is_array ( $ value ) ) { $ key = $ value ; $ value = [ ] ; } if ( true === $ value ) { $ value = $ key ; } if ( is_string ( $ value ) ) { $ value = [ $ standardProperty => $ value , ] ; } if ( $ objectClass ) { if ( empty ( $ value ) ) { $ value = [ ] ; } $ value = $ this -> makeClearedDataObject ( $ objectClass , $ value , $ parentKey ? $ parentKey . ".{$key}" : null ) ; } $ normalized [ $ key ] = $ value ; } return $ normalized ; }
Normalizes a standard array property .
52,204
protected function normalizeKeyLessArrayProperty ( array $ source , $ standardProperty , $ objectClass = null , $ parentKey = null ) { $ normalized = [ ] ; foreach ( $ source as $ index => $ value ) { if ( is_string ( $ value ) ) { $ value = [ $ standardProperty => $ value , ] ; } if ( $ objectClass ) { $ value = $ this -> makeClearedDataObject ( $ objectClass , $ value , $ parentKey ? $ parentKey . ".{$index}" : null ) ; } $ normalized [ ] = $ value ; } return $ normalized ; }
Normalizes a standard array property for inassociative data .
52,205
protected function makeClearedDataObject ( $ objectClass , array $ data , $ parentKey = null ) { $ object = new $ objectClass ( ) ; $ object -> clear ( ) ; try { $ object -> setAttributes ( $ data ) ; } catch ( ModelConfigurationDataException $ e ) { throw $ e -> setDotKey ( $ parentKey . ( $ e -> getDotKey ( ) ? '.' . $ e -> getDotKey ( ) : null ) ) ; } return $ object ; }
Makes a fresh dataobject with its defaults cleared before filling it with data .
52,206
protected function getLinkForReferenceModel ( Model $ model ) { $ routeName = $ this -> getRouteHelper ( ) -> getRouteNameForModelClass ( get_class ( $ model ) , true ) ; $ action = $ this -> determineRouteAction ( $ model ) ; return route ( $ routeName . '.' . $ action , $ model -> getKey ( ) ) ; }
Returns action link for given model .
52,207
protected function determineRouteAction ( Model $ model ) { $ routeHelper = $ this -> getRouteHelper ( ) ; $ permissionPrefix = $ routeHelper -> getPermissionPrefixForModelSlug ( $ routeHelper -> getRouteSlugForModelClass ( get_class ( $ model ) ) ) ; if ( ! cms_auth ( ) -> can ( $ permissionPrefix . 'edit' ) ) { return 'show' ; } return 'edit' ; }
Returns route action for given model .
52,208
protected function castValueAsJson ( $ value ) { $ value = $ this -> asJson ( $ value ) ; if ( $ value === false ) { throw new \ RuntimeException ( sprintf ( "Unable to encode value [%s] for element [%s] to JSON: %s." , $ this -> getName ( ) , get_class ( $ this ) , json_last_error_msg ( ) ) ) ; } return $ value ; }
Cast the given value to JSON .
52,209
protected function castValue ( $ value ) { if ( is_null ( $ value ) ) { return $ value ; } if ( $ this -> isElementOfDate ( ) && $ this -> isDateCastable ( ) ) { return $ this -> fromDateTime ( $ value ) ; } switch ( $ this -> getCast ( ) ) { case 'int' : case 'integer' : return ( int ) $ value ; case 'real' : case 'float' : case 'double' : return ( float ) $ value ; case 'string' : return ( string ) $ value ; case 'bool' : case 'boolean' : return ( bool ) $ value ; case 'object' : return $ this -> fromJson ( $ value , true ) ; case 'array' : case 'json' : return $ this -> fromJson ( $ value ) ; case 'collection' : return new Collection ( $ this -> fromJson ( $ value ) ) ; case 'comma' : return $ this -> fromCommaSeparated ( $ value ) ; default : return $ value ; } }
Cast a value to a native PHP type .
52,210
protected function getValueFromModel ( $ model ) { if ( ! ( $ model instanceof Model ) ) { return null ; } return get_class ( $ model ) . static :: CLASS_AND_KEY_SEPARATOR . $ model -> getKey ( ) ; }
Returns the value for a single related model .
52,211
protected function storeActiveTranslationLocale ( $ request ) { $ locale = $ request -> input ( DefaultModelController :: ACTIVE_TRANSLATION_LOCALE_KEY ) ; if ( ! $ locale ) return ; $ helper = app ( TranslationLocaleHelperInterface :: class ) ; $ helper -> setActiveLocale ( $ locale ) ; }
Stores active translation locale in session .
52,212
protected function parseObserver ( $ observer ) { if ( preg_match ( '([^A-Za-z0-9_/\\\\])' , $ observer ) ) { throw new InvalidArgumentException ( 'Observer name contains invalid characters.' ) ; } $ observer = str_replace ( '/' , '\\' , $ observer ) ; if ( ! Str :: startsWith ( $ observer , [ $ rootNamespace = $ this -> laravel -> getNamespace ( ) , '\\' ] ) ) { $ observer = $ rootNamespace . $ this -> getComponentNamespace ( ) . '\Observers\\' . rtrim ( $ observer , 'Observer' ) . 'Observer' ; } return $ observer ; }
Get the fully - qualified observer class name .
52,213
protected function setCurrentModelClass ( ) { if ( ! $ this -> router -> isModelRoute ( ) ) { $ this -> currentModelClass = null ; return $ this ; } $ info = $ this -> repository -> getByKey ( $ this -> router -> getModuleKeyForCurrentRoute ( ) ) ; if ( $ info ) { $ this -> currentModelClass = $ info -> original_model ? : $ info -> model ; } else { $ this -> currentModelClass = null ; } $ this -> activeModelClass = $ this -> currentModelClass ; return $ this ; }
Sets the active and current model class based on the current request .
52,214
public function info ( ) { if ( empty ( $ this -> activeModelClass ) ) { $ info = false ; } else { $ info = $ this -> repository -> getByModelClass ( $ this -> activeModelClass ) ; } $ this -> activeModelClass = $ this -> currentModelClass ; return $ info ; }
Returns model information data object for active model .
52,215
protected function makeModelListColumnDataForAttributeData ( ModelAttributeData $ attribute , ModelInformationInterface $ info ) { $ primaryIncrementing = $ attribute -> name === $ this -> model -> getKeyName ( ) && $ info -> incrementing ; $ sortable = ( $ attribute -> isNumeric ( ) || in_array ( $ attribute -> cast , [ AttributeCast :: BOOLEAN , AttributeCast :: DATE , AttributeCast :: STRING , ] ) && ! in_array ( $ attribute -> type , [ 'text' , 'longtext' , 'mediumtext' , 'blob' , 'longblob' , 'mediumblob' , ] ) ) ; $ sortDirection = 'asc' ; if ( $ primaryIncrementing || in_array ( $ attribute -> cast , [ AttributeCast :: BOOLEAN , AttributeCast :: DATE ] ) ) { $ sortDirection = 'desc' ; } return new ModelListColumnData ( [ 'source' => $ attribute -> name , 'strategy' => $ this -> determineListDisplayStrategyForAttribute ( $ attribute ) , 'style' => $ primaryIncrementing ? 'primary-id' : null , 'editable' => $ attribute -> fillable , 'sortable' => $ sortable , 'sort_strategy' => $ attribute -> translated ? 'translated' : null , 'sort_direction' => $ sortDirection , ] ) ; }
Makes data set for list column given attribute data .
52,216
protected function makeModelListColumnDataForRelationData ( ModelRelationData $ relation ) { return new ModelListColumnData ( [ 'source' => $ relation -> method , 'strategy' => $ this -> determineListDisplayStrategyForRelation ( $ relation ) , 'label' => ucfirst ( str_replace ( '_' , ' ' , snake_case ( $ relation -> method ) ) ) , 'sortable' => false , ] ) ; }
Makes data set for list column given relation data .
52,217
protected function initializeForModelRoute ( ) { $ this -> moduleKey = $ this -> routeHelper -> getModuleKeyForCurrentRoute ( ) ; $ this -> modelSlug = $ this -> routeHelper -> getModelSlugForCurrentRoute ( ) ; $ this -> permissionPrefix = $ this -> routeHelper -> getPermissionPrefixForModelSlug ( $ this -> modelSlug ) ; if ( ! $ this -> moduleKey ) { throw new RuntimeException ( "Could not determine module key for route" ) ; } $ this -> modelInformation = $ this -> infoRepository -> getByKey ( $ this -> modelSlug ) ; if ( ! $ this -> modelInformation ) { throw new RuntimeException ( "Could not load information for model key '{$this->modelSlug}'" ) ; } $ this -> routePrefix = $ this -> routeHelper -> getRouteNameForModelClass ( $ this -> modelInformation -> modelClass ( ) , true ) ; return $ this ; }
Initializes controller and checks context expecting a model route .
52,218
protected function getFormFieldStoreStrategyParametersForField ( ModelFormFieldDataInterface $ field ) { $ strategy = $ field -> store_strategy ? : '' ; $ pos = strpos ( $ strategy , ':' ) ; if ( false === $ pos ) { return [ ] ; } return array_map ( 'trim' , explode ( ',' , substr ( $ strategy , $ pos + 1 ) ) ) ; }
Returns parameters that should be passed into the store strategy instance .
52,219
protected function performEnrichment ( ) { if ( ! count ( $ this -> info -> form -> fields ) ) { return ; } $ this -> layoutFields = $ this -> info -> form -> getLayoutFormFieldKeys ( ) ; $ this -> enrichCreateRules ( ) -> enrichUpdateRules ( ) ; }
Performs enrichment of validation rules based on form field strategies .
52,220
protected function getCustomizedRuleKeysToExclude ( array $ customRules ) { $ keys = [ ] ; foreach ( $ customRules as $ key => $ ruleParts ) { if ( false === $ ruleParts || empty ( $ ruleParts ) ) { $ keys [ ] = $ key ; } } return $ keys ; }
Returns keys for rules that should not be included by custom configuration .
52,221
protected function getCustomizedRuleKeysToKeepDefault ( array $ customRules ) { $ keys = [ ] ; foreach ( $ customRules as $ key => $ ruleParts ) { if ( is_string ( $ ruleParts ) && is_numeric ( $ key ) ) { $ keys [ ] = $ ruleParts ; } } return $ keys ; }
Returns keys for rules that should be kept from the default generated rules even when in replace mode .
52,222
protected function enrichRulesNew ( array $ customRules , array $ generatedRules , $ replace , array $ excludeKeys , array $ keepDefaultKeys , array $ generatedRulesMap ) { $ result = $ customRules ; foreach ( $ keepDefaultKeys as $ key ) { if ( ! array_key_exists ( $ key , $ generatedRules ) ) { continue ; } $ result [ $ key ] = $ generatedRules [ $ key ] ; } if ( ! $ replace ) { foreach ( $ generatedRulesMap as $ fieldKey => $ ruleKeys ) { if ( in_array ( $ fieldKey , $ excludeKeys ) ) { continue ; } foreach ( $ ruleKeys as $ key ) { if ( in_array ( $ key , $ excludeKeys ) || in_array ( $ key , $ keepDefaultKeys ) || array_key_exists ( $ key , $ result ) || ! array_key_exists ( $ key , $ generatedRules ) ) { continue ; } $ result [ $ key ] = $ generatedRules [ $ key ] ; } } } $ result = $ this -> getRuleMerger ( ) -> convertRequiredForTranslatedFields ( $ result ) ; return $ this -> castValidationRulesToArray ( $ result ) ; }
Enriches rules and returns the enriched rules array .
52,223
protected function getFormFieldGeneratedRules ( $ forCreate = true ) { $ this -> generatedRulesMap = [ ] ; $ rules = [ ] ; foreach ( $ this -> info -> form -> fields as $ field ) { try { $ this -> getFormFieldGeneratedRule ( $ field , $ forCreate , $ rules ) ; } catch ( Exception $ e ) { $ section = 'form.validation.' . ( $ forCreate ? 'create' : 'update' ) ; throw ( new ModelInformationEnrichmentException ( "Issue with validation rules for form field '{$field->key()}' ({$section}): \n{$e->getMessage()}" , $ e -> getCode ( ) , $ e ) ) -> setSection ( $ section ) -> setKey ( $ field -> key ( ) ) ; } } return $ rules ; }
Returns rules determined by form field strategies .
52,224
protected function getFormFieldGeneratedRule ( ModelFormFieldDataInterface $ field , $ forCreate , array & $ rules ) { $ this -> generatedRulesMap [ $ field -> key ( ) ] = [ ] ; if ( ! $ this -> isFormFieldRelevant ( $ field , $ forCreate ) ) { return ; } $ fieldRules = $ this -> getAndMergeFormFieldRulesForStrategyAndBasedOnModelInformation ( $ field , $ forCreate ) ; if ( $ field -> translated ( ) ) { array_map ( function ( ValidationRuleDataInterface $ rule ) { $ rule -> setIsTranslated ( ) ; } , $ fieldRules ) ; } $ fieldRules = $ this -> replaceFieldKeyPlaceholderInValidationRules ( $ field , $ fieldRules ) ; foreach ( $ fieldRules as $ rule ) { if ( empty ( $ rule -> key ( ) ) ) { $ rule -> setKey ( $ field -> key ( ) ) ; $ rules [ $ field -> key ( ) ] = $ rule ; $ this -> generatedRulesMap [ $ field -> key ( ) ] [ ] = $ field -> key ( ) ; continue ; } $ rule -> prefixKey ( $ field -> key ( ) ) ; $ rules [ $ rule -> key ( ) ] = $ rule ; $ this -> generatedRulesMap [ $ field -> key ( ) ] [ ] = $ rule -> key ( ) ; } }
Updates collected rules array with rules based on form field data .
52,225
protected function normalizeValidationRuleSourceDataFromConfig ( array $ rules ) { $ filteredRules = array_filter ( $ rules , function ( $ rule , $ key ) { return false !== $ rule && ! empty ( $ rule ) && ! ( is_string ( $ rule ) && is_numeric ( $ key ) ) ; } , ARRAY_FILTER_USE_BOTH ) ; return $ this -> normalizeValidationRuleSourceData ( $ filteredRules ) ; }
Normalizes custom configured rules data to include only specified rules .
52,226
protected function normalizeValidationRuleSourceData ( $ rules ) { if ( false === $ rules || empty ( $ rules ) ) { return [ ] ; } if ( is_string ( $ rules ) ) { $ rules = ( array ) $ rules ; } if ( ! is_array ( $ rules ) ) { throw new UnexpectedValueException ( "Form field base validation rules not array or arrayable" ) ; } $ rules = array_map ( [ $ this , 'normalizeRulesProperty' ] , $ rules , array_keys ( $ rules ) ) ; $ rules = $ this -> getRuleMerger ( ) -> collapseRulesForDuplicateKeys ( $ rules ) ; return array_combine ( array_map ( function ( ValidationRuleDataInterface $ rule ) { return $ rule -> key ( ) ? : '' ; } , $ rules ) , $ rules ) ; }
Normalizes generated validation rule data to an array of data object instances .
52,227
protected function normalizeRulesProperty ( $ rules , $ key ) { if ( $ rules instanceof ValidationRuleDataInterface ) { return $ rules ; } if ( is_string ( $ rules ) ) { $ rules = explode ( '|' , $ rules ) ; } if ( ! is_array ( $ rules ) ) { $ rules = ( array ) $ rules ; } if ( $ key === static :: VALIDATION_RULE_DATA_KEY ) { return $ this -> makeValidationRuleDataFromSpecialArraySyntax ( $ rules , '' ) ; } if ( is_array ( array_get ( $ rules , static :: VALIDATION_RULE_DATA_KEY ) ) ) { return $ this -> makeValidationRuleDataFromSpecialArraySyntax ( $ rules [ static :: VALIDATION_RULE_DATA_KEY ] , $ key ) ; } return new ValidationRuleData ( $ rules , is_numeric ( $ key ) ? null : $ key ) ; }
Normalizes rules data for a single validation rule key .
52,228
protected function makeValidationRuleDataFromSpecialArraySyntax ( array $ rules , $ key ) { $ data = new ValidationRuleData ( array_get ( $ rules , 'rules' , [ ] ) , array_get ( $ rules , 'key' , is_numeric ( $ key ) ? null : $ key ) ) ; if ( array_has ( $ rules , 'translated' ) ) { $ data -> setIsTranslated ( ( bool ) $ rules [ 'translated' ] ) ; } if ( array_has ( $ rules , 'locale_index' ) ) { if ( ( int ) $ rules [ 'locale_index' ] < 1 ) { throw new UnexpectedValueException ( "Locale index for configured validation data cannot be less than 1 (key/index: {$key})" ) ; } $ data -> setLocaleIndex ( ( int ) $ rules [ 'locale_index' ] ) ; } return $ data ; }
Makes a validation rule data object from a special configuration array .
52,229
protected function getFormFieldModelInformationBasedRules ( ModelFormFieldDataInterface $ field ) { $ key = $ field -> key ( ) ; $ modelInformation = $ this -> getModelInformation ( ) ; if ( array_key_exists ( $ key , $ modelInformation -> attributes ) ) { return $ this -> getAttributeValidationResolver ( ) -> determineValidationRules ( $ modelInformation -> attributes [ $ key ] , $ field ) ; } if ( array_key_exists ( $ key , $ modelInformation -> relations ) ) { return $ this -> getRelationValidationResolver ( ) -> determineValidationRules ( $ modelInformation -> relations [ $ key ] , $ field ) ; } return false ; }
Returns validation rules based on model information for a given form field .
52,230
public function store ( Model $ model , $ source , $ value ) { if ( ! $ this -> isTranslated ( ) ) { $ this -> performStore ( $ model , $ source , $ value ) ; return ; } if ( ! is_array ( $ value ) ) { throw new UnexpectedValueException ( "Value should be in per-locale array format for translatable data" ) ; } foreach ( $ value as $ locale => $ singleValue ) { if ( null === $ singleValue && ! $ this -> isNullable ( ) ) { $ singleValue = '' ; } $ this -> performStore ( $ model -> translateOrNew ( $ locale ) , $ source , $ singleValue ) ; } }
Stores a submitted value on a model
52,231
public function validationRules ( ModelInformationInterface $ modelInformation = null , $ create ) { if ( ! ( $ field = $ this -> formFieldData ) ) { return false ; } return $ this -> getStrategySpecificRules ( $ field ) ; }
Returns validation rules to use for submitted form data for this strategy .
52,232
public function mapWebRoutes ( Router $ router ) { $ permissionPrefix = $ this -> routeHelper -> getPermissionPrefixForModelSlug ( $ this -> getModelSlug ( ) ) ; $ router -> group ( [ 'prefix' => $ this -> getRoutePrefix ( ) , 'as' => $ this -> getRouteNamePrefix ( ) , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}*" ) ] , ] , function ( Router $ router ) use ( $ permissionPrefix ) { $ controller = $ this -> getModelWebController ( ) ; $ router -> get ( '/' , [ 'as' => 'index' , 'uses' => $ controller . '@index' , ] ) ; $ router -> get ( 'create' , [ 'as' => 'create' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}create" ) ] , 'uses' => $ controller . '@create' , ] ) ; $ router -> post ( '/' , [ 'as' => 'store' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}create" ) , StoreActiveFormContext :: class , ] , 'uses' => $ controller . '@store' , ] ) ; $ router -> post ( 'filter' , [ 'as' => 'filter' , 'uses' => $ controller . '@filter' , ] ) ; $ router -> get ( 'export/{strategy}' , [ 'as' => 'export' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}export" ) ] , 'uses' => $ controller . '@export' , ] ) ; $ router -> get ( '{key}' , [ 'as' => 'show' , 'uses' => $ controller . '@show' , ] ) ; $ router -> get ( '{key}/edit' , [ 'as' => 'edit' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}edit" ) ] , 'uses' => $ controller . '@edit' , ] ) ; $ router -> put ( '{key}/activate' , [ 'as' => 'activate' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}edit" ) ] , 'uses' => $ controller . '@activate' , ] ) ; $ router -> put ( '{key}/position' , [ 'as' => 'position' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}edit" ) ] , 'uses' => $ controller . '@position' , ] ) ; $ router -> get ( '{key}/deletable' , [ 'as' => 'deletable' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}delete" ) ] , 'uses' => $ controller . '@deletable' , ] ) ; $ router -> put ( '{key}' , [ 'as' => 'update' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}edit" ) , StoreActiveFormContext :: class , ] , 'uses' => $ controller . '@update' , ] ) ; $ router -> delete ( '{key}' , [ 'as' => 'destroy' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}delete" ) ] , 'uses' => $ controller . '@destroy' , ] ) ; } ) ; }
Generates web routes for the module given a contextual router instance . Note that the module is responsible for ACL - checks including route - based .
52,233
public function mapApiRoutes ( Router $ router ) { $ permissionPrefix = $ this -> routeHelper -> getPermissionPrefixForModelSlug ( $ this -> getModelSlug ( ) ) ; $ router -> group ( [ 'prefix' => $ this -> getRoutePrefix ( ) , 'as' => $ this -> getRouteNamePrefix ( ) , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}*" ) ] , ] , function ( Router $ router ) use ( $ permissionPrefix ) { $ controller = $ this -> getModelApiController ( ) ; $ router -> get ( '/' , [ 'as' => 'index' , 'uses' => $ controller . '@index' , ] ) ; $ router -> get ( 'create' , [ 'as' => 'create' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}create" ) ] , 'uses' => $ controller . '@create' , ] ) ; $ router -> post ( '/' , [ 'as' => 'store' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}create" ) ] , 'uses' => $ controller . '@store' , ] ) ; $ router -> get ( '{key}' , [ 'as' => 'show' , 'uses' => $ controller . '@show' , ] ) ; $ router -> get ( '{key}/edit' , [ 'as' => 'edit' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}edit" ) ] , 'uses' => $ controller . '@edit' , ] ) ; $ router -> put ( '{key}' , [ 'as' => 'update' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}edit" ) ] , 'uses' => $ controller . '@update' , ] ) ; $ router -> delete ( '{key}' , [ 'as' => 'destroy' , 'middleware' => [ cms_mw_permission ( "{$permissionPrefix}delete" ) ] , 'uses' => $ controller . '@destroy' , ] ) ; } ) ; }
Generates API routes for the module given a contextual router instance . Note that the module is responsible for ACL - checks including route - based .
52,234
public function getMenuPresence ( ) { return [ 'id' => 'models.' . $ this -> getRouteSlug ( ) , 'label' => ucfirst ( $ this -> getInformation ( ) -> labelPlural ( false ) ) , 'label_translated' => $ this -> getInformation ( ) -> labelPluralTranslationKey ( ) , 'type' => MenuPresenceType :: ACTION , 'action' => $ this -> routeHelper -> getRouteNameForModelClass ( $ this -> class , true ) . '.index' , 'parameters' => [ 'home' => true , ] , 'permissions' => [ "models.{$this->getRouteSlug()}.*" , ] , ] ; }
Returns data for CMS menu presence .
52,235
protected function getFileValidationRules ( ) { $ rules = array_get ( $ this -> field -> options , 'validation' , [ ] ) ; if ( is_string ( $ rules ) ) { if ( empty ( $ rules ) ) { $ rules = 'image' ; } elseif ( ! preg_match ( '#(^|\|)image($|\|)#' , $ rules ) ) { $ rules .= '|image' ; } } elseif ( ! in_array ( 'image' , $ rules ) ) { array_unshift ( $ rules , 'image' ) ; } return $ rules ; }
Returns validation rules that should be applied to the uploaded file .
52,236
public function determineValidationRules ( ModelAttributeData $ attribute , ModelFormFieldData $ field ) { $ rules = [ ] ; $ required = $ field -> required ( ) ; switch ( $ attribute -> cast ) { case AttributeCast :: BOOLEAN : $ required = false ; break ; case AttributeCast :: INTEGER : $ rules [ ] = 'integer' ; break ; case AttributeCast :: FLOAT : $ rules [ ] = 'numeric' ; break ; case AttributeCast :: STRING : switch ( $ attribute -> type ) { case 'enum' : $ rules [ ] = 'in:' . implode ( ',' , $ attribute -> values ) ; break ; case 'year' : $ rules [ ] = 'digits:4' ; break ; case 'varchar' : $ rules [ ] = 'string' ; if ( $ attribute -> length ) { $ rules [ ] = 'max:' . $ attribute -> length ; } break ; case 'tinytext' : $ rules [ ] = 'string' ; $ rules [ ] = 'max:255' ; break ; case 'char' : $ rules [ ] = 'string' ; $ rules [ ] = 'max:' . $ attribute -> length ; break ; case 'text' : case 'mediumtext' : case 'longtext' : case 'blob' ; case 'mediumblob' ; case 'longblob' ; case 'binary' ; case 'varbinary' ; $ rules [ ] = 'string' ; break ; } break ; case AttributeCast :: DATE : switch ( $ attribute -> type ) { case 'date' : case 'datetime' : case 'timestamp' : $ rules [ ] = 'date' ; break ; case 'time' : $ rules [ ] = 'regex:#^\d{1,2}:\d{1,2}(:\d{1,2})?$#' ; break ; } break ; case AttributeCast :: JSON : $ rules [ ] = 'json' ; break ; } if ( $ required ) { $ rules [ ] = 'required' ; } else { $ rules [ ] = 'nullable' ; } return $ rules ; }
Determines validation rules for given attribute data .
52,237
public function analyze ( ModelInformationInterface $ information ) { $ this -> info = $ information ; $ this -> performStep ( ) ; return $ this -> info ; }
Performs analysis .
52,238
protected function databaseAnalyzer ( ) { $ driver = $ this -> model ( ) -> getConnection ( ) -> getDriverName ( ) ; $ class = config ( "cms-models.analyzer.database.driver.{$driver}" ) ; if ( $ class ) { return app ( $ class ) ; } return app ( DatabaseAnalyzerInterface :: class ) ; }
Returns configured or bound database analyzer .
52,239
protected function isAttributeBoolean ( ModelAttributeData $ attribute ) { if ( $ attribute -> cast == AttributeCast :: BOOLEAN ) { return true ; } return $ attribute -> type === 'tinyint' && $ attribute -> length === 1 ; }
Returns whether an attribute should be taken for a boolean .
52,240
protected function getCmsDocBlockTags ( ReflectionMethod $ method ) { if ( ! ( $ docBlock = $ method -> getDocComment ( ) ) ) { return [ ] ; } $ factory = DocBlockFactory :: createInstance ( ) ; $ doc = $ factory -> create ( $ docBlock ) ; $ tags = $ doc -> getTagsByName ( 'cms' ) ; if ( ! $ tags || ! count ( $ tags ) ) { return [ ] ; } $ cmsTags = [ ] ; foreach ( $ tags as $ tag ) { if ( ! method_exists ( $ tag , 'getDescription' ) ) { continue ; } $ description = trim ( $ tag -> getDescription ( ) ) ; if ( preg_match ( '#\s+#' , $ description ) ) { list ( $ firstWord , $ parameters ) = preg_split ( '#\s+#' , $ description , 2 ) ; } else { $ firstWord = $ description ; $ parameters = '' ; } $ firstWord = strtolower ( $ firstWord ) ; if ( $ firstWord == 'relation' ) { $ cmsTags [ 'relation' ] = true ; continue ; } if ( $ firstWord == 'ignore' ) { $ cmsTags [ 'ignore' ] = true ; continue ; } if ( $ firstWord == 'morph' ) { if ( ! $ parameters ) continue ; $ models = array_map ( 'trim' , explode ( ',' , $ parameters ) ) ; if ( ! array_key_exists ( 'morph' , $ cmsTags ) ) { $ cmsTags [ 'morph' ] = [ ] ; } $ cmsTags [ 'morph' ] = array_merge ( $ cmsTags [ 'morph' ] , $ models ) ; $ cmsTags [ 'morph' ] = array_unique ( $ cmsTags [ 'morph' ] ) ; continue ; } } return $ cmsTags ; }
Returns associative array representing the CMS docblock tag content .
52,241
protected function getMethodBody ( ReflectionMethod $ method ) { $ file = new SplFileObject ( $ method -> getFileName ( ) ) ; $ methodBodyLines = iterator_to_array ( new LimitIterator ( $ file , $ method -> getStartLine ( ) , $ method -> getEndLine ( ) - $ method -> getStartLine ( ) ) ) ; return implode ( "\n" , $ methodBodyLines ) ; }
Returns the PHP code for a ReflectionMethod .
52,242
protected function getRelationNameFromRelationInstance ( Relation $ relation ) { foreach ( $ this -> info -> relations as $ relationData ) { if ( $ relation == $ this -> model ( ) -> { $ relationData -> method } ( ) ) { return $ relationData -> method ; } } return null ; }
Returns relation method name related to a relation instance .
52,243
protected function addIncludesDefault ( $ relation , $ value = null ) { $ includes = array_get ( $ this -> info -> includes , 'default' , [ ] ) ; if ( null !== $ value ) { $ includes [ $ relation ] = $ value ; } elseif ( ! array_key_exists ( $ relation , $ includes ) && ! in_array ( $ relation , $ includes ) ) { $ includes [ ] = $ relation ; } $ this -> info -> includes [ 'default' ] = $ includes ; return $ this ; }
Adds an entry to the default includes .
52,244
public function normalizeDateValue ( $ date , $ outFormat = 'Y-m-d H:i:s' , $ inFormat = null , $ nullable = false ) { if ( empty ( $ outFormat ) ) { $ outFormat = 'Y-m-d H:i:s' ; } if ( $ date instanceof DateTime ) { return $ date -> format ( $ outFormat ) ; } if ( null === $ date ) { if ( $ nullable ) { return null ; } return $ this -> makeEmptyStringDate ( $ outFormat ) ; } if ( null === $ inFormat ) { try { $ date = new Carbon ( $ date ) ; } catch ( \ Exception $ e ) { if ( $ nullable ) { return null ; } return $ this -> makeEmptyStringDate ( $ outFormat ) ; } } else { $ date = DateTime :: createFromFormat ( $ inFormat , $ date ) ; } return $ date -> format ( $ outFormat ) ; }
Normalizes a date value to a given output string format .
52,245
protected function getTranslationsRelation ( $ query ) { $ model = $ query -> getModel ( ) ; if ( ! method_exists ( $ model , 'translations' ) ) { throw new RuntimeException ( 'Model ' . get_class ( $ model ) . ' is not a translated model.' ) ; } return $ model -> translations ( ) ; }
Returns relation instance for translations .
52,246
protected function renderedShowFieldStrategies ( Model $ model ) { $ views = [ ] ; foreach ( $ this -> getModelInformation ( ) -> show -> fields as $ key => $ data ) { if ( ! $ this -> allowedToUseShowFieldData ( $ data ) ) { continue ; } try { $ instance = $ this -> getShowFieldFactory ( ) -> make ( $ data -> strategy ) ; $ instance -> setOptions ( $ data -> options ( ) ) ; if ( $ data -> source ) { if ( isset ( $ this -> getModelInformation ( ) -> attributes [ $ data -> source ] ) ) { $ instance -> setAttributeInformation ( $ this -> getModelInformation ( ) -> attributes [ $ data -> source ] ) ; } } } catch ( Exception $ e ) { $ message = "Failed to make show field strategy for '{$key}': \n{$e->getMessage()}" ; throw new StrategyRenderException ( $ message , $ e -> getCode ( ) , $ e ) ; } try { $ views [ $ key ] = $ instance -> render ( $ model , $ data -> source ) ; } catch ( Exception $ e ) { $ message = "Failed to render show field '{$key}' for strategy " . get_class ( $ instance ) . ": \n{$e->getMessage()}" ; throw new StrategyRenderException ( $ message , $ e -> getCode ( ) , $ e ) ; } } return $ views ; }
Renders Vies or HTML for show field strategies .
52,247
protected function applyLocaleRestriction ( $ query , $ locale = null , $ allowFallback = true ) { $ localeKey = $ this -> getLocaleKey ( ) ; $ locale = $ locale ? : app ( ) -> getLocale ( ) ; $ fallback = $ this -> getFallbackLocale ( ) ; if ( $ allowFallback && $ fallback && $ fallback != $ locale ) { $ query -> where ( function ( $ query ) use ( $ localeKey , $ locale , $ fallback ) { $ query -> where ( $ localeKey , $ locale ) -> orWhere ( $ localeKey , $ fallback ) ; } ) ; return ; } $ query -> where ( $ localeKey , $ locale ) ; }
Applies locale - based restriction to a translations relation query .
52,248
public function mergeSharedConfiguredRulesWithCreateOrUpdate ( $ shared , $ specific , $ replace = false ) { if ( $ specific === false ) { return [ ] ; } if ( $ specific === null || $ specific === true ) { $ specific = [ ] ; } if ( $ replace ) { $ sharedKeys = array_filter ( $ specific , function ( $ value , $ key ) { return is_string ( $ value ) && is_numeric ( $ key ) ; } , ARRAY_FILTER_USE_BOTH ) ; $ specific = array_filter ( $ specific , function ( $ value , $ key ) use ( $ shared ) { return ! is_string ( $ value ) || ! is_numeric ( $ key ) || ! array_key_exists ( $ value , $ shared ) ; } , ARRAY_FILTER_USE_BOTH ) ; return array_merge ( array_only ( $ shared , $ sharedKeys ) , $ specific ) ; } return array_merge ( $ shared ? : [ ] , $ specific ) ; }
Merges model configuration rules for the shared section with the create or update section .
52,249
public function convertRequiredForTranslatedFields ( array $ rules ) { $ isTranslatedKeys = [ ] ; $ hasRequiredKeys = [ ] ; foreach ( $ rules as $ index => $ rule ) { if ( ! $ rule -> isTranslated ( ) ) { continue ; } $ isTranslatedKeys [ ] = $ rule -> key ( ) ? : '' ; if ( in_array ( 'required' , $ rule -> rules ( ) ) ) { $ hasRequiredKeys [ $ index ] = $ rule -> key ( ) ? : '' ; } } foreach ( $ hasRequiredKeys as $ index => $ key ) { $ rule = $ rules [ $ index ] ; $ this -> replaceRequiredForRequiredWith ( $ rule , array_diff ( $ isTranslatedKeys , [ $ key ] ) ) ; } return $ rules ; }
Updates a list of validation rules to make required fields work in a per - locale context .
52,250
protected function replaceRequiredForRequiredWith ( ValidationRuleDataInterface $ rule , array $ requiredWithKeys ) { $ rules = array_diff ( $ rule -> rules ( ) , [ 'required' ] ) ; if ( count ( $ requiredWithKeys ) ) { $ rules [ ] = 'required_with:' . implode ( ',' , $ requiredWithKeys ) ; } $ rule -> setRules ( $ rules ) ; }
Updates the rules in a validation data object to replace the required rule with a required_with rule for multiple fields .
52,251
protected function getRuleType ( $ rule ) { if ( ! is_string ( $ rule ) ) { return '' ; } if ( false === ( $ pos = strpos ( $ rule , ':' ) ) ) { return $ rule ; } return substr ( $ rule , 0 , $ pos ) ; }
Returns a rule type for a given validation rule .
52,252
public function write ( ModelInformationInterface $ information , array $ config = [ ] ) { $ this -> information = $ information ; $ this -> config = $ config ; $ this -> content = [ ] ; $ this -> path = $ this -> getInformationTargetPath ( ) ; $ keys = $ this -> getKeysToWrite ( ) ; $ this -> checkWhetherFileAlreadyExists ( ) ; foreach ( $ keys as $ key ) { $ this -> writeKey ( $ key ) ; } $ this -> writeContentToFile ( ) ; return $ this -> path ; }
Writes model information basics to a cms model file .
52,253
protected function writeContentToFile ( ) { $ content = '<?php' . PHP_EOL . PHP_EOL . 'return ' . $ this -> getCleanContent ( ) . ';' . PHP_EOL ; try { File :: put ( $ this -> path , $ content ) ; } catch ( Exception $ e ) { throw ( new ModelInformationFileWriteFailureException ( "Failed to write '{$this->path}', make sure the directory exists and is writable" , $ e -> getCode ( ) , $ e ) ) -> setModelClass ( $ this -> information -> modelClass ( ) ) ; } }
Writes the array model information content to file .
52,254
protected function getCleanContent ( ) { $ content = var_export ( $ this -> content , true ) ; $ content = preg_replace ( '#^(\s*)array\s*\(#i' , '\\1[' , $ content ) ; $ content = preg_replace ( '#=>(\s*)array\s*\(#is' , '=> [' , $ content ) ; $ content = preg_replace ( '#^(\s*)\),#im' , '\\1],' , $ content ) ; $ content = substr ( $ content , 0 , - 1 ) . ']' ; $ content = preg_replace ( '#(\s*)\d+\s*=>\s*(.*)#i' , '\\1\\2' , $ content ) ; $ content = $ this -> replaceDoubleSpaceIndentWithCustomSpaceIndent ( $ content ) ; return $ content ; }
Returns clean writable php array content .
52,255
protected function getInformationTargetPath ( ) { if ( $ path = array_get ( $ this -> config , 'path' ) ) { return $ path ; } return rtrim ( $ this -> getInformationTargetBasePath ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ this -> getInformationTargetRelativePath ( ) ; }
Returns the path where the models should be stored .
52,256
protected function getKeysToWrite ( ) { $ keys = array_get ( $ this -> config , 'keys' , [ '*' ] ) ; if ( in_array ( '*' , $ keys ) ) { return $ this -> getWritableDefaultKeys ( ) ; } return $ keys ; }
Returns the keys that should be written .
52,257
public function display ( ) { if ( $ this -> label_translated ) { return cms_trans ( $ this -> label_translated ) ; } if ( $ this -> label ) { return $ this -> label ; } return snake_case ( $ this -> method , ' ' ) ; }
Returns display text for the scope .
52,258
protected function markRequiredForNestedLayoutChildren ( $ nodes = null , $ parentKey = null ) { if ( null === $ nodes ) { $ nodes = $ this -> info -> form -> layout ( ) ; } if ( is_array ( $ nodes ) ) { $ required = null ; foreach ( $ nodes as $ key => $ value ) { try { $ oneRequired = $ this -> markRequiredForNestedLayoutChildren ( $ value , 'children.' . $ key ) ; } catch ( ModelConfigurationDataException $ e ) { throw $ e -> setDotKey ( $ parentKey . ( $ e -> getDotKey ( ) ? '.' . $ e -> getDotKey ( ) : null ) ) ; } if ( ! $ required && $ oneRequired ) { $ required = true ; } } return $ required ; } if ( $ nodes instanceof ModelFormLayoutNodeInterface ) { if ( $ nodes instanceof ModelFormFieldLabelData ) { return false ; } $ required = $ this -> markRequiredForNestedLayoutChildren ( $ nodes -> children ( ) , $ parentKey ) ; if ( null === $ nodes -> required ) { $ nodes -> required = $ required ; } return $ nodes -> required ; } if ( is_string ( $ nodes ) ) { if ( array_key_exists ( $ nodes , $ this -> info -> form -> fields ) ) { return $ this -> info -> form -> fields [ $ nodes ] -> required ( ) ; } return false ; } return null ; }
Enriches existing layout data with required state for parent nodes .
52,259
public function setPosition ( Model $ model , $ position ) { if ( $ position === $ model -> getListifyPosition ( ) ) { return $ position ; } switch ( $ position ) { case null : case OrderablePosition :: REMOVE : $ model -> removeFromList ( ) ; break ; case OrderablePosition :: UP : $ model -> moveHigher ( ) ; break ; case OrderablePosition :: DOWN : $ model -> moveLower ( ) ; break ; case OrderablePosition :: TOP : if ( $ model -> isInList ( ) ) { $ model -> moveToTop ( ) ; } else { $ model -> insertAt ( ) ; } break ; case OrderablePosition :: BOTTOM : if ( $ model -> isInList ( ) ) { $ model -> moveToBottom ( ) ; } else { $ model -> insertAt ( ) ; $ model -> moveToBottom ( ) ; } break ; default : $ position = ( int ) $ position ; $ model -> insertAt ( $ position ) ; } return $ model -> getListifyPosition ( ) ; }
Sets a new orderable position for a model .
52,260
public function hasTabs ( ) : bool { if ( ! $ this -> layout || ! count ( $ this -> layout ) ) { return false ; } foreach ( $ this -> layout as $ key => $ value ) { if ( $ value instanceof ModelFormTabDataInterface ) { return true ; } } return false ; }
Returns whether a layout with tabs is set .
52,261
public function tabs ( ) : array { if ( ! $ this -> layout || ! count ( $ this -> layout ) ) { return [ ] ; } $ tabs = [ ] ; foreach ( $ this -> layout as $ key => $ value ) { if ( $ value instanceof ModelFormTabDataInterface ) { $ tabs [ $ key ] = $ value ; } } return $ tabs ; }
Returns only the tabs from the layout set .
52,262
public function layout ( ) : array { if ( $ this -> layout && count ( $ this -> layout ) ) { return $ this -> layout ; } return array_keys ( $ this -> fields ) ; }
Returns the layout that should be used for displaying the edit form .
52,263
protected function getNestedFormFieldKeys ( ModelFormLayoutNodeInterface $ node = null ) : array { if ( null === $ node ) { $ children = $ this -> layout ( ) ; } else { $ children = $ node -> children ( ) ; } $ fieldKeys = [ ] ; foreach ( $ children as $ key => $ value ) { if ( $ value instanceof ModelFormLayoutNodeInterface ) { $ fieldKeys = array_merge ( $ fieldKeys , $ this -> getNestedFormFieldKeys ( $ value ) ) ; continue ; } if ( is_string ( $ value ) ) { $ fieldKeys [ ] = $ value ; } } return $ fieldKeys ; }
Returns a list of form field keys recursively for a given layout node .
52,264
public function determineListDisplayStrategy ( ModelRelationData $ data ) { switch ( $ data -> type ) { case RelationType :: BELONGS_TO : case RelationType :: BELONGS_TO_THROUGH : case RelationType :: HAS_ONE : case RelationType :: MORPH_ONE : case RelationType :: MORPH_TO : return ListDisplayStrategy :: RELATION_REFERENCE ; case RelationType :: BELONGS_TO_MANY : case RelationType :: HAS_MANY : case RelationType :: MORPH_MANY : case RelationType :: MORPH_TO_MANY : case RelationType :: MORPHED_BY_MANY : return ListDisplayStrategy :: RELATION_COUNT ; } return null ; }
Determines a list display strategy string for given relation data .
52,265
public function determineFormDisplayStrategy ( ModelRelationData $ data ) { $ type = null ; switch ( $ data -> type ) { case RelationType :: BELONGS_TO : case RelationType :: BELONGS_TO_THROUGH : case RelationType :: MORPH_ONE : case RelationType :: HAS_ONE : $ type = FormDisplayStrategy :: RELATION_SINGLE_AUTOCOMPLETE ; break ; case RelationType :: BELONGS_TO_MANY : case RelationType :: HAS_MANY : case RelationType :: MORPH_MANY : case RelationType :: MORPH_TO_MANY : case RelationType :: MORPHED_BY_MANY : $ type = FormDisplayStrategy :: RELATION_PLURAL_AUTOCOMPLETE ; break ; case RelationType :: MORPH_TO : $ type = FormDisplayStrategy :: RELATION_SINGLE_MORPH_AUTOCOMPLETE ; break ; } return $ type ; }
Determines a form display strategy string for given relation data .
52,266
public function determineFormStoreStrategy ( ModelRelationData $ data ) { $ type = null ; $ parameters = [ ] ; switch ( $ data -> type ) { case RelationType :: BELONGS_TO : case RelationType :: BELONGS_TO_THROUGH : case RelationType :: MORPH_ONE : case RelationType :: HAS_ONE : $ type = FormStoreStrategy :: RELATION_SINGLE_KEY ; break ; case RelationType :: BELONGS_TO_MANY : case RelationType :: HAS_MANY : case RelationType :: MORPH_MANY : case RelationType :: MORPH_TO_MANY : case RelationType :: MORPHED_BY_MANY : $ type = FormStoreStrategy :: RELATION_PLURAL_KEYS ; break ; case RelationType :: MORPH_TO : $ type = FormStoreStrategy :: RELATION_SINGLE_MORPH ; break ; } if ( $ data -> translated ) { $ parameters [ ] = 'translated' ; } if ( count ( $ parameters ) ) { $ type .= ':' . implode ( ',' , $ parameters ) ; } return $ type ; }
Determines a form store strategy string for given relation data .
52,267
public function determineFormStoreOptions ( ModelRelationData $ data ) { $ options = [ ] ; switch ( $ data -> type ) { case RelationType :: MORPH_TO : $ models = $ this -> determineMorphModelsForRelationData ( $ data ) ; if ( count ( $ models ) ) { $ options [ 'models' ] = $ models ; } break ; } return $ options ; }
Determines a form store s options for given relation data .
52,268
protected function getAvailableExportStrategyKeys ( ) { if ( empty ( $ this -> getModelInformation ( ) -> export -> strategies ) ) { return [ ] ; } $ keys = array_keys ( $ this -> getModelInformation ( ) -> export -> strategies ) ; return array_filter ( $ keys , [ $ this , 'isExportStrategyAvailable' ] ) ; }
Returns list of export strategy keys that are availabe for the current user .
52,269
protected function getExportDownloadFilename ( $ strategy , $ extension ) { return Carbon :: now ( ) -> format ( 'Y-m-d_H-i' ) . ' - ' . $ this -> getModelSlug ( ) . '.' . ltrim ( $ extension , '.' ) ; }
Returns filename for an export download .
52,270
protected function isExportStrategyAvailable ( $ strategy ) { if ( ! array_key_exists ( $ strategy , $ this -> getModelInformation ( ) -> export -> strategies ) ) { return false ; } $ strategyInfo = $ this -> getModelInformation ( ) -> export -> strategies [ $ strategy ] ; $ permissions = $ strategyInfo -> permissions ( ) ; if ( false === $ permissions ) { $ permissions = [ $ this -> getPermissionPrefix ( ) . 'export' ] ; } if ( count ( $ permissions ) && ! $ this -> getCore ( ) -> auth ( ) -> can ( $ permissions ) ) { return false ; } return true ; }
Returns whether a given strategy key corresponds to a usable export strategy .
52,271
protected function getExportStrategyInstance ( $ strategy ) { $ strategyData = array_get ( $ this -> getModelInformation ( ) -> export -> strategies , $ strategy ) ; $ instance = $ this -> getExportStrategyFactory ( ) -> make ( $ strategyData -> strategy ) ; if ( $ strategyData ) { $ instance -> setStrategyData ( $ strategyData ) ; } return $ instance ; }
Returns prepared exporter strategy instance for a given strategy string .
52,272
protected function getRelevantFormFieldKeys ( $ creating = false ) { $ fieldKeys = $ this -> getModelInformation ( ) -> form -> getLayoutFormFieldKeys ( ) ; $ fieldKeys = array_filter ( $ fieldKeys , function ( $ key ) use ( $ creating ) { if ( ! array_key_exists ( $ key , $ this -> getModelInformation ( ) -> form -> fields ) ) { throw new UnexpectedValueException ( "Layout field key '{$key}' not found in fields form data for " . $ this -> getModelInformation ( ) -> modelClass ( ) ) ; } $ fieldData = $ this -> getModelInformation ( ) -> form -> fields [ $ key ] ; if ( ! $ this -> allowedToUseFormFieldData ( $ fieldData ) ) { return false ; } if ( $ creating ) { return $ fieldData -> create ( ) ; } return $ fieldData -> update ( ) ; } ) ; return $ fieldKeys ; }
Returns a list of form field keys relevant for the current context depending on whether the model is being created or updated .
52,273
protected function getFormFieldValuesFromModel ( Model $ model , array $ keys ) { $ values = [ ] ; foreach ( $ keys as $ key ) { $ field = $ this -> getModelFormFieldDataForKey ( $ key ) ; $ instance = $ this -> getFormFieldStoreStrategyInstanceForField ( $ field ) ; $ instance -> setFormFieldData ( $ field ) ; $ instance -> setParameters ( $ this -> getFormFieldStoreStrategyParametersForField ( $ field ) ) ; if ( ! $ model -> exists && $ this -> isFieldValueBeDerivableFromListParent ( $ field -> key ) ) { try { $ values [ $ key ] = $ instance -> valueForListParentKey ( $ this -> getListParentRecordKey ( ) ) ; } catch ( Exception $ e ) { $ message = "Failed retrieving value for form field '{$key}' (using " . get_class ( $ instance ) . " (valueForListParentKey)): \n{$e->getMessage()}" ; throw new StrategyRetrievalException ( $ message , $ e -> getCode ( ) , $ e ) ; } continue ; } try { $ values [ $ key ] = $ instance -> retrieve ( $ model , $ field -> source ? : $ field -> key ) ; } catch ( Exception $ e ) { $ message = "Failed retrieving value for form field '{$key}' (using " . get_class ( $ instance ) . "): \n{$e->getMessage()}" ; throw new StrategyRetrievalException ( $ message , $ e -> getCode ( ) , $ e ) ; } } return $ values ; }
Collects and returns current values for fields by key from a model .
52,274
protected function getNormalizedFormFieldErrors ( ) { $ viewBags = session ( 'errors' ) ; if ( ! ( $ viewBags instanceof ViewErrorBag ) || ! count ( $ viewBags ) ) { return [ ] ; } $ errorBag = head ( $ viewBags -> getBags ( ) ) ; if ( ! $ errorBag -> any ( ) ) { return [ ] ; } $ normalized = [ ] ; foreach ( $ errorBag -> toArray ( ) as $ field => $ errors ) { array_set ( $ normalized , $ field , $ errors ) ; } return $ normalized ; }
Returns associative array with form validation errors keyed by field keys .
52,275
protected function getErrorCountsPerTabPane ( ) { $ normalizedErrorKeys = array_keys ( $ this -> getNormalizedFormFieldErrors ( ) ) ; if ( ! count ( $ normalizedErrorKeys ) ) { return [ ] ; } $ errorCount = [ ] ; foreach ( $ this -> getModelInformation ( ) -> form -> layout ( ) as $ key => $ node ) { if ( ! ( $ node instanceof ModelFormTabDataInterface ) ) { continue ; } $ fieldKeys = $ this -> getFieldKeysForTab ( $ key ) ; $ errorCount [ $ key ] = count ( array_intersect ( $ normalizedErrorKeys , $ fieldKeys ) ) ; } return $ errorCount ; }
Returns the error count keyed by tab pane keys .
52,276
protected function getFieldKeysForTab ( $ tab ) { $ layout = $ this -> getModelInformation ( ) -> form -> layout ( ) ; if ( ! array_key_exists ( $ tab , $ layout ) ) { return [ ] ; } $ tabData = $ layout [ $ tab ] ; if ( ! ( $ tabData instanceof ModelFormTabDataInterface ) ) { return [ ] ; } return $ tabData -> descendantFieldKeys ( ) ; }
Returns the form field keys that are descendants of a given tab pane .
52,277
public function setMax ( int $ value ) { $ this -> max = $ value ; $ this -> addValidationRule ( 'max:' . $ value ) ; return $ this ; }
Set maximum number .
52,278
public function setMin ( int $ value ) { $ this -> min = $ value ; $ this -> addValidationRule ( 'min:' . $ value ) ; return $ this ; }
Set minimum number .
52,279
public function export ( $ query , $ path ) { $ this -> query = $ query ; $ this -> modelClass = get_class ( $ query -> getModel ( ) ) ; return $ this -> generateExport ( $ path ) ; }
Exports data returned by a model listing query to a file .
52,280
public function download ( $ query , $ filename ) { $ this -> query = $ query ; $ this -> modelClass = get_class ( $ query -> getModel ( ) ) ; $ temporary = $ this -> generateExport ( ) ; if ( ! $ temporary ) { return false ; } return response ( ) -> download ( $ temporary , $ filename ) -> deleteFileAfterSend ( true ) ; }
Exports data returned by listing query and returns a download response for it .
52,281
protected function getColumnStrategyInstances ( ) { if ( ! $ this -> exportInfo ) { throw new UnexpectedValueException ( "No export information set, cannot determine column strategies" ) ; } $ information = $ this -> getModelInformation ( ) ; $ factory = $ this -> getExportColumnStrategyFactory ( ) ; $ instances = [ ] ; foreach ( $ this -> exportInfo -> columns as $ key => $ columnData ) { $ instance = $ factory -> make ( $ columnData -> strategy ) ; $ instance -> setColumnInformation ( $ columnData ) ; if ( $ columnData -> source ) { if ( isset ( $ information -> attributes [ $ columnData -> source ] ) ) { $ instance -> setAttributeInformation ( $ information -> attributes [ $ columnData -> source ] ) ; } } $ instances [ $ key ] = $ instance -> initialize ( $ this -> modelClass ) ; } if ( ! count ( $ instances ) ) { throw new UnexpectedValueException ( "No strategies for any columns, cannot perform export" ) ; } return $ instances ; }
Returns list of export column strategy instances in order .
52,282
protected function displayKeys ( $ keys ) { $ this -> info ( 'Model keys:' ) ; foreach ( $ keys as $ key ) { $ this -> comment ( ' ' . $ key ) ; } $ this -> info ( '' ) ; }
Display model keys in console .
52,283
protected function displayAll ( array $ data ) { foreach ( $ data as $ key => $ single ) { $ this -> display ( $ key , $ single ) ; } }
Displays data in console for a list of model information arrays .
52,284
protected function display ( $ key , array $ data ) { if ( $ pluck = $ this -> option ( 'pluck' ) ) { if ( ! array_has ( $ data , $ pluck ) ) { $ this -> warn ( "Nothing to pluck for '{$pluck}'." ) ; return ; } $ data = array_get ( $ data , $ pluck ) ; } $ this -> comment ( $ key ) ; if ( $ this -> option ( 'keys' ) && is_array ( $ data ) ) { $ data = array_keys ( $ data ) ; } $ this -> getDumper ( ) -> dump ( $ data ) ; $ this -> info ( '' ) ; }
Displays data in the console for a single information array .
52,285
protected function isTargetDateOnly ( ) { if ( ! $ this -> filterData ) { return false ; } $ target = $ this -> filterData -> target ( ) ; if ( ! array_key_exists ( $ target , $ this -> getModelInformation ( ) -> attributes ) ) { return false ; } return ( $ this -> getModelInformation ( ) -> attributes [ $ target ] -> type == 'date' ) ; }
Returns whether the target date column is date only .
52,286
protected function isModelDeletable ( Model $ model ) { $ this -> lastUnmetDeleteConditionMessage = null ; if ( ! $ this -> isAuthorizedToDelete ( ) ) { $ this -> lastUnmetDeleteConditionMessage = $ this -> getUnmetConditionMessageForAuthorizationFailure ( ) ; return false ; } $ info = $ this -> getModelInformation ( ) ; if ( ! $ info -> allowDelete ( ) ) { $ this -> lastUnmetDeleteConditionMessage = $ this -> getUnmetConditionMessageForDisallowedFailure ( ) ; return false ; } $ condition = $ info -> deleteCondition ( ) ; if ( ! $ condition ) { return true ; } $ strategies = $ this -> interpretDeleteCondition ( $ condition ) ; foreach ( $ strategies as $ strategy => $ parameters ) { $ factory = app ( DeleteConditionStrategyFactoryInterface :: class ) ; $ strategy = $ factory -> make ( $ strategy ) ; if ( ! $ strategy -> check ( $ model , $ parameters ) ) { $ this -> lastUnmetDeleteConditionMessage = $ strategy -> message ( ) ; return false ; } } return true ; }
Returns whether a given model may be deleted .
52,287
protected function interpretDeleteCondition ( $ condition ) { if ( false !== strpos ( $ condition , '|' ) ) { $ condition = explode ( '|' , $ condition ) ; } if ( is_array ( $ condition ) ) { $ normalized = [ ] ; foreach ( $ condition as $ partialCondition ) { $ normalized = array_merge ( $ normalized , $ this -> interpretDeleteCondition ( $ partialCondition ) ) ; } return $ normalized ; } if ( false !== strpos ( $ condition , ':' ) ) { list ( $ strategy , $ parameters ) = explode ( ':' , $ condition , 2 ) ; $ parameters = explode ( ',' , $ parameters ) ; } else { $ strategy = $ condition ; $ parameters = [ ] ; } return [ $ strategy => $ parameters ] ; }
Interprets delete condition value and returns an array of delete condition classes
52,288
public function references ( ModelMetaReferenceRequest $ request ) { $ modelClass = $ request -> input ( 'model' ) ; $ type = $ request -> input ( 'type' ) ; $ key = $ request -> input ( 'key' ) ; $ referenceData = $ this -> getModelMetaReferenceData ( $ modelClass , $ type , $ key ) ; if ( ! $ referenceData ) { abort ( 404 , "Could not determine reference for {$modelClass} (type: {$type}, key: {$key})" ) ; } $ search = $ request -> input ( 'search' ) ; if ( is_array ( $ referenceData ) ) { $ references = [ ] ; foreach ( $ referenceData as $ singleReferenceData ) { $ references [ $ singleReferenceData -> model ] = $ this -> getReferencesByMetaData ( $ singleReferenceData , $ search ) ; } } else { $ references = $ this -> getReferencesByMetaData ( $ referenceData , $ search ) ; } return response ( ) -> json ( $ references ) ; }
Looks up model references by an optional search term .
52,289
protected function getReferencesByMetaData ( ModelMetaReference $ data , $ search = null ) { $ references = $ this -> referenceRepository -> getReferencesForModelMetaReference ( $ data , $ search ) -> all ( ) ; return $ this -> formatReferenceOutput ( $ references ) ; }
Returns references by meta reference data .
52,290
protected function getModelMetaReferenceData ( $ modelClass , $ type , $ key ) { $ info = $ this -> getCmsModelInformation ( $ modelClass ) ; if ( ! $ info ) { abort ( 404 , "{$modelClass} is not a CMS model" ) ; } $ nestedModels = $ this -> referenceDataProvider -> getNestedModelClassesByType ( $ info , $ type , $ key ) ; if ( false !== $ nestedModels ) { $ data = [ ] ; foreach ( $ nestedModels as $ nestedModelClass ) { $ data [ $ nestedModelClass ] = $ this -> referenceDataProvider -> getForInformationByType ( $ info , $ type , $ key , $ nestedModelClass ) ; } } else { $ data = $ this -> referenceDataProvider -> getForInformationByType ( $ info , $ type , $ key ) ; } if ( ! $ data ) { abort ( 404 , "Could not retrieve reference data for {$type}, key: {$key}" ) ; } return $ data ; }
Returns reference data from CMS model information by type .
52,291
protected function getReferencesForModelKeys ( array $ keys , $ targetModel = null ) { $ keys = array_filter ( $ keys ) ; if ( ! count ( $ keys ) ) { return [ ] ; } $ referenceData = $ this -> getReferenceDataProvider ( ) -> getForModelClassByType ( $ this -> model , 'form.field' , $ this -> field -> key ( ) , $ targetModel ) ; if ( ! $ referenceData ) { return [ ] ; } $ references = [ ] ; foreach ( $ keys as $ key ) { $ references [ $ key ] = $ this -> getReferenceRepository ( ) -> getReferenceForModelMetaReferenceByKey ( $ referenceData , $ key ) ; } return $ references ; }
Returns references for model keys as an array keyed per model key .
52,292
protected function getModelDisplayLabel ( $ modelClass ) { $ info = $ this -> getModelInformation ( $ modelClass ) ; if ( $ info ) { return ucfirst ( $ info -> labelPlural ( ) ) ; } return $ this -> makeModelDisplayValueFromModelClass ( $ modelClass ) ; }
Get displayable text for a given model class .
52,293
protected function makeModelDisplayValueFromModelClass ( $ modelClass ) { $ stripPrefix = config ( 'cms-models.collector.models-namespace' ) ; if ( $ stripPrefix && starts_with ( $ modelClass , $ stripPrefix ) ) { $ modelClass = trim ( substr ( $ modelClass , 0 , strlen ( $ stripPrefix ) ) , '\\' ) ; } return ucfirst ( str_replace ( '\\' , ' ' , $ modelClass ) ) ; }
Returns displayable text for a given model class based only on the class name .
52,294
protected function determineBestMinimumInputLength ( ) { $ info = $ this -> getModelInformation ( get_class ( $ this -> model ) ) ; $ models = $ this -> getReferenceDataProvider ( ) -> getNestedModelClassesByType ( $ info , 'form.field' , $ this -> field -> key ( ) ) ; if ( $ models && count ( $ models ) ) { $ total = array_reduce ( $ models , function ( $ carry , $ modelClass ) { return $ carry + $ this -> getCountForModel ( $ modelClass ) ; } ) ; } else { $ referenceData = $ this -> getReferenceDataProvider ( ) -> getForInformationByType ( $ info , 'form.field' , $ this -> field -> key ( ) ) ; if ( false === $ referenceData ) { return 1 ; } $ total = $ this -> getCountForModel ( $ referenceData -> model ( ) ) ; } if ( null === $ total ) { return 1 ; } if ( $ total > static :: AUTOCOMPLETE_INPUT_THRESHOLD_THREE ) { return 3 ; } if ( $ total > static :: AUTOCOMPLETE_INPUT_THRESHOLD_TWO ) { return 2 ; } if ( $ total > static :: AUTOCOMPLETE_INPUT_THRESHOLD_ONE ) { return 1 ; } return 0 ; }
Returns the best minimum input length for autocomplete input ajax triggers .
52,295
protected function getCountForModel ( $ modelClass ) { if ( ! is_a ( $ modelClass , Model :: class , true ) ) { throw new UnexpectedValueException ( "'{$modelClass}' is not an Eloquent model class." ) ; } return $ modelClass :: withoutGlobalScopes ( ) -> count ( ) ? : 0 ; }
Returns total count for a model classname .
52,296
protected function renderTranslatedFields ( array $ locales , $ value , $ originalValue , array $ errors ) { $ rendered = [ ] ; foreach ( $ locales as $ locale ) { $ rendered [ $ locale ] = $ this -> renderField ( $ this -> getValueForLocale ( $ locale , $ value ) , $ this -> getValueForLocale ( $ locale , $ originalValue ) , $ this -> getErrorsForLocale ( $ locale , $ errors ) , $ locale ) ; } return view ( static :: FORM_FIELD_TRANSLATED_VIEW , [ 'field' => $ this -> field , 'locales' => $ locales , 'value' => $ value , 'errors' => $ errors , 'localeRendered' => $ rendered , ] ) ; }
Returns a rendered set of translated form fields .
52,297
protected function initializeForModelRoute ( ) { $ routeHelper = $ this -> getRouteHelper ( ) ; $ this -> modelSlug = $ routeHelper -> getModelSlugForCurrentRoute ( ) ; if ( ! $ this -> modelSlug ) { throw new RuntimeException ( "Could not determine model slug for route in request" ) ; } $ this -> modelInformation = $ this -> getModelInformationRepository ( ) -> getByKey ( $ this -> modelSlug ) ; if ( ! $ this -> modelInformation ) { throw new RuntimeException ( "Could not load information for model slug '{$this->modelSlug}' in request" ) ; } return $ this ; }
Initializes form request and checks context expecting a model route .
52,298
protected function getRedirectUrl ( ) { if ( $ this -> ajax ( ) ) { $ lastSegment = last ( $ this -> segments ( ) ) ; $ routePrefix = $ this -> getRouteHelper ( ) -> getRouteNameForModelClass ( $ this -> modelInformation -> modelClass ( ) , true ) ; if ( $ lastSegment == $ this -> getRouteHelper ( ) -> getModelSlugForCurrentRoute ( ) && $ this -> method ( ) == 'POST' ) { $ this -> redirect = cms_route ( "{$routePrefix}.create" ) ; } elseif ( $ lastSegment == 'update' ) { $ this -> redirect = cms_route ( "{$routePrefix}.edit" ) ; } } return parent :: getRedirectUrl ( ) ; }
Overridden to make sure AJAX calls don t redirect based on session where it can be prevented .
52,299
protected function getParsedColumnTable ( $ table ) { $ this -> validateTableName ( $ table ) ; $ table = DB :: connection ( $ this -> connection ) -> select ( DB :: connection ( $ this -> connection ) -> raw ( "PRAGMA table_info({$table});" ) ) ; $ columns = [ ] ; foreach ( $ table as $ columnData ) { $ columns [ $ columnData -> name ] = ( array ) $ columnData ; } return $ columns ; }
Returns a parsed set of columns for a table .