idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
23,400
protected function processExistingItems ( ) { $ loadedIndexes = $ loadedGroups = [ ] ; $ loadValue = $ this -> getLoadValue ( ) ; if ( ! $ this -> useGroups && $ this -> minItems > 0 ) { if ( ! is_array ( $ loadValue ) ) { $ loadValue = [ ] ; for ( $ i = 0 ; $ i < $ this -> minItems ; $ i ++ ) { $ loadValue [ $ i ] = [...
Processes existing form data and applies it to the form widgets .
23,401
protected function makeItemFormWidget ( $ index = 0 , $ groupCode = null ) { $ configDefinition = $ this -> useGroups ? $ this -> getGroupFormFieldConfig ( $ groupCode ) : $ this -> form ; $ config = $ this -> makeConfig ( $ configDefinition ) ; $ config -> model = $ this -> model ; $ config -> data = $ this -> getLoad...
Creates a form widget based on a field index and optional group code .
23,402
protected function getLoadValueFromIndex ( $ index ) { $ loadValue = $ this -> getLoadValue ( ) ; if ( ! is_array ( $ loadValue ) ) { $ loadValue = [ ] ; } return array_get ( $ loadValue , $ index , [ ] ) ; }
Returns the load data at a given index .
23,403
protected function getGroupFormFieldConfig ( $ code ) { if ( ! $ code ) { return null ; } $ fields = array_get ( $ this -> groupDefinitions , $ code . '.fields' ) ; if ( ! $ fields ) { return null ; } return [ 'fields' => $ fields ] ; }
Returns the form field configuration for a group identified by code .
23,404
protected function processGroupMode ( ) { $ palette = [ ] ; if ( ! $ group = $ this -> getConfig ( 'groups' , [ ] ) ) { $ this -> useGroups = false ; return ; } if ( is_string ( $ group ) ) { $ group = $ this -> makeConfig ( $ group ) ; } foreach ( $ group as $ code => $ config ) { $ palette [ $ code ] = [ 'code' => $ ...
Process features related to group mode .
23,405
public function withComponent ( $ components , $ callback = null ) { return $ this -> filter ( function ( $ object ) use ( $ components , $ callback ) { $ hasComponent = false ; foreach ( ( array ) $ components as $ componentName ) { if ( ! $ callback && $ object -> hasComponent ( $ componentName ) ) { $ hasComponent =...
Returns objects that use the supplied component .
23,406
public function where ( $ property , $ value , $ strict = true ) { return $ this -> filter ( function ( $ object ) use ( $ property , $ value , $ strict ) { if ( ! array_key_exists ( $ property , $ object -> settings ) ) { return false ; } return $ strict ? $ object -> settings [ $ property ] === $ value : $ object -> ...
Returns objects whose properties match the supplied value .
23,407
public function whereComponent ( $ components , $ property , $ value , $ strict = false ) { return $ this -> filter ( function ( $ object ) use ( $ components , $ property , $ value , $ strict ) { $ hasComponent = false ; foreach ( ( array ) $ components as $ componentName ) { if ( ! $ componentAlias = $ object -> hasC...
Returns objects whose component properties match the supplied value .
23,408
private function overwriteConfig ( ) { foreach ( array_keys ( $ this -> config ( ) ) as $ config ) { $ this -> config = $ config ; $ this -> configToEnv ( ) ; } }
Overwrite config file
23,409
private function parseConfigFile ( ) { $ lines = [ ] ; foreach ( $ this -> lines ( ) as $ line ) { $ keys = $ this -> config ( ) [ $ this -> config ] ; $ lines [ ] = $ this -> parseLine ( $ line , $ keys ) ; } $ this -> writeToEnv ( "\n" ) ; return implode ( '' , $ lines ) ; }
Parse config file line by line
23,410
public function combineToFile ( $ assets = [ ] , $ destination , $ localPath = null ) { $ this -> storagePath = null ; if ( $ localPath ) { if ( substr ( $ localPath , - 1 ) !== '/' ) { $ localPath = $ localPath . '/' ; } $ assets = array_map ( function ( $ asset ) use ( $ localPath ) { if ( substr ( $ asset , 0 , 1 ) ...
Combines a collection of assets files to a destination file
23,411
protected function prepareAssets ( array $ assets ) { if ( ! is_array ( $ assets ) ) { $ assets = [ $ assets ] ; } $ combineJs = [ ] ; $ combineCss = [ ] ; foreach ( $ assets as $ asset ) { if ( substr ( $ asset , 0 , 1 ) == '@' ) { $ combineJs [ ] = $ asset ; $ combineCss [ ] = $ asset ; continue ; } $ extension = Fil...
Prepares an array of assets by normalizing the collection and processing aliases .
23,412
protected function prepareRequest ( array $ assets , $ localPath = null ) { if ( substr ( $ localPath , - 1 ) != '/' ) { $ localPath = $ localPath . '/' ; } $ this -> localPath = $ localPath ; $ this -> storagePath = storage_path ( 'cms/combiner/assets' ) ; list ( $ assets , $ extension ) = $ this -> prepareAssets ( $ ...
Combines asset file references of a single type to produce a URL reference to the combined contents .
23,413
protected function setHashOnCombinerFilters ( $ hash ) { $ allFilters = call_user_func_array ( 'array_merge' , $ this -> getFilters ( ) ) ; foreach ( $ allFilters as $ filter ) { if ( method_exists ( $ filter , 'setHash' ) ) { $ filter -> setHash ( $ hash ) ; } } }
Busts the cache based on a different cache key .
23,414
protected function getDeepHashFromAssets ( $ assets ) { $ key = '' ; $ assetFiles = array_map ( function ( $ file ) { return file_exists ( $ file ) ? $ file : File :: symbolizePath ( $ file , null ) ? : $ this -> localPath . $ file ; } , $ assets ) ; foreach ( $ assetFiles as $ file ) { $ filters = $ this -> getFilters...
Returns a deep hash on filters that support it .
23,415
protected function getCombinedUrl ( $ outputFilename = 'undefined.css' ) { $ combineAction = 'System\Classes\Controller@combine' ; $ actionExists = Route :: getRoutes ( ) -> getByAction ( $ combineAction ) !== null ; if ( $ actionExists ) { return Url :: action ( $ combineAction , [ $ outputFilename ] , false ) ; } ret...
Returns the URL used for accessing the combined files .
23,416
protected function getTargetPath ( $ path = null ) { if ( $ path === null ) { $ baseUri = substr ( Request :: getBaseUrl ( ) , strlen ( Request :: getBasePath ( ) ) ) ; $ path = $ baseUri . '/combine' ; } if ( strpos ( $ path , '/' ) === 0 ) { $ path = substr ( $ path , 1 ) ; } $ path = str_replace ( '.' , '-' , $ path...
Returns the target path for use with the combiner . The target path helps generate relative links within CSS .
23,417
public function registerFilter ( $ extension , $ filter ) { if ( is_array ( $ extension ) ) { foreach ( $ extension as $ _extension ) { $ this -> registerFilter ( $ _extension , $ filter ) ; } return ; } $ extension = strtolower ( $ extension ) ; if ( ! isset ( $ this -> filters [ $ extension ] ) ) { $ this -> filters ...
Register a filter to apply to the combining process .
23,418
public function resetFilters ( $ extension = null ) { if ( $ extension === null ) { $ this -> filters = [ ] ; } else { $ this -> filters [ $ extension ] = [ ] ; } return $ this ; }
Clears any registered filters .
23,419
public function getFilters ( $ extension = null ) { if ( $ extension === null ) { return $ this -> filters ; } elseif ( isset ( $ this -> filters [ $ extension ] ) ) { return $ this -> filters [ $ extension ] ; } else { return null ; } }
Returns filters .
23,420
public function registerBundle ( $ files , $ destination = null , $ extension = null ) { if ( ! is_array ( $ files ) ) { $ files = [ $ files ] ; } $ firstFile = array_values ( $ files ) [ 0 ] ; if ( $ extension === null ) { $ extension = File :: extension ( $ firstFile ) ; } $ extension = strtolower ( trim ( $ extensio...
Registers bundle .
23,421
public function getBundles ( $ extension = null ) { if ( $ extension === null ) { return $ this -> bundles ; } elseif ( isset ( $ this -> bundles [ $ extension ] ) ) { return $ this -> bundles [ $ extension ] ; } else { return null ; } }
Returns bundles .
23,422
public function registerAlias ( $ alias , $ file , $ extension = null ) { if ( $ extension === null ) { $ extension = File :: extension ( $ file ) ; } $ extension = strtolower ( $ extension ) ; if ( ! isset ( $ this -> aliases [ $ extension ] ) ) { $ this -> aliases [ $ extension ] = [ ] ; } $ this -> aliases [ $ exten...
Register an alias to use for a longer file reference .
23,423
public function resetAliases ( $ extension = null ) { if ( $ extension === null ) { $ this -> aliases = [ ] ; } else { $ this -> aliases [ $ extension ] = [ ] ; } return $ this ; }
Clears any registered aliases .
23,424
public function getAliases ( $ extension = null ) { if ( $ extension === null ) { return $ this -> aliases ; } elseif ( isset ( $ this -> aliases [ $ extension ] ) ) { return $ this -> aliases [ $ extension ] ; } else { return null ; } }
Returns aliases .
23,425
protected function putCache ( $ cacheKey , array $ cacheInfo ) { $ cacheKey = 'combiner.' . $ cacheKey ; if ( Cache :: has ( $ cacheKey ) ) { return false ; } $ this -> putCacheIndex ( $ cacheKey ) ; Cache :: forever ( $ cacheKey , base64_encode ( serialize ( $ cacheInfo ) ) ) ; return true ; }
Stores information about a asset collection against a cache identifier .
23,426
protected function getCache ( $ cacheKey ) { $ cacheKey = 'combiner.' . $ cacheKey ; if ( ! Cache :: has ( $ cacheKey ) ) { return false ; } return @ unserialize ( @ base64_decode ( Cache :: get ( $ cacheKey ) ) ) ; }
Look up information about a cache identifier .
23,427
protected function getCacheKey ( array $ assets ) { $ cacheKey = $ this -> localPath . implode ( '|' , $ assets ) ; if ( $ this -> useDeepHashing ) { $ cacheKey .= $ this -> getDeepHashFromAssets ( $ assets ) ; } $ dataHolder = ( object ) [ 'key' => $ cacheKey ] ; Event :: fire ( 'cms.combiner.getCacheKey' , [ $ this ,...
Builds a unique string based on assets
23,428
public static function resetCache ( ) { if ( Cache :: has ( 'combiner.index' ) ) { $ index = ( array ) @ unserialize ( @ base64_decode ( Cache :: get ( 'combiner.index' ) ) ) ? : [ ] ; foreach ( $ index as $ cacheKey ) { Cache :: forget ( $ cacheKey ) ; } Cache :: forget ( 'combiner.index' ) ; } CacheHelper :: instance...
Resets the combiner cache
23,429
protected function putCacheIndex ( $ cacheKey ) { $ index = [ ] ; if ( Cache :: has ( 'combiner.index' ) ) { $ index = ( array ) @ unserialize ( @ base64_decode ( Cache :: get ( 'combiner.index' ) ) ) ? : [ ] ; } if ( in_array ( $ cacheKey , $ index ) ) { return false ; } $ index [ ] = $ cacheKey ; Cache :: forever ( '...
Adds a cache identifier to the index store used for performing a reset of the cache .
23,430
public static function getComponentsPropertyConfig ( $ component , $ addAliasProperty = true , $ returnArray = false ) { $ result = [ ] ; if ( $ addAliasProperty ) { $ property = [ 'property' => 'oc.alias' , 'title' => Lang :: get ( 'cms::lang.component.alias' ) , 'description' => Lang :: get ( 'cms::lang.component.ali...
Returns a component property configuration as a JSON string or array .
23,431
public static function getComponentPropertyValues ( $ component ) { $ result = [ ] ; $ result [ 'oc.alias' ] = $ component -> alias ; $ properties = $ component -> defineProperties ( ) ; foreach ( $ properties as $ name => $ params ) { $ result [ $ name ] = $ component -> property ( $ name ) ; } return json_encode ( $ ...
Returns a component property values .
23,432
public static function getComponentName ( $ component ) { $ details = $ component -> componentDetails ( ) ; $ name = $ details [ 'name' ] ?? 'cms::lang.component.unnamed' ; return Lang :: get ( $ name ) ; }
Returns a component name .
23,433
public static function getComponentDescription ( $ component ) { $ details = $ component -> componentDetails ( ) ; $ name = $ details [ 'description' ] ?? 'cms::lang.component.no_description' ; return Lang :: get ( $ name ) ; }
Returns a component description .
23,434
protected function loadItems ( ) { foreach ( $ this -> callbacks as $ callback ) { $ callback ( $ this ) ; } $ plugins = $ this -> pluginManager -> getPlugins ( ) ; foreach ( $ plugins as $ id => $ plugin ) { $ items = $ plugin -> registerNavigation ( ) ; if ( ! is_array ( $ items ) ) { continue ; } $ this -> registerM...
Loads the menu items from modules and plugins
23,435
public function addMainMenuItems ( $ owner , array $ definitions ) { foreach ( $ definitions as $ code => $ definition ) { $ this -> addMainMenuItem ( $ owner , $ code , $ definition ) ; } }
Dynamically add an array of main menu items
23,436
public function addMainMenuItem ( $ owner , $ code , array $ definition ) { $ itemKey = $ this -> makeItemKey ( $ owner , $ code ) ; if ( isset ( $ this -> items [ $ itemKey ] ) ) { $ definition = array_merge ( ( array ) $ this -> items [ $ itemKey ] , $ definition ) ; } $ item = ( object ) array_merge ( self :: $ main...
Dynamically add a single main menu item
23,437
public function addSideMenuItems ( $ owner , $ code , array $ definitions ) { foreach ( $ definitions as $ sideCode => $ definition ) { $ this -> addSideMenuItem ( $ owner , $ code , $ sideCode , ( array ) $ definition ) ; } }
Dynamically add an array of side menu items
23,438
public function addSideMenuItem ( $ owner , $ code , $ sideCode , array $ definition ) { $ itemKey = $ this -> makeItemKey ( $ owner , $ code ) ; if ( ! isset ( $ this -> items [ $ itemKey ] ) ) { return false ; } $ mainItem = $ this -> items [ $ itemKey ] ; $ definition = array_merge ( $ definition , [ 'code' => $ sid...
Dynamically add a single side menu item
23,439
public function listSideMenuItems ( $ owner = null , $ code = null ) { $ activeItem = null ; if ( $ owner !== null && $ code !== null ) { $ activeItem = @ $ this -> items [ $ this -> makeItemKey ( $ owner , $ code ) ] ; } else { foreach ( $ this -> listMainMenuItems ( ) as $ item ) { if ( $ this -> isMainMenuItemActive...
Returns a list of side menu items for the currently active main menu item . The currently active main menu item is set with the setContext methods .
23,440
public function setContext ( $ owner , $ mainMenuItemCode , $ sideMenuItemCode = null ) { $ this -> setContextOwner ( $ owner ) ; $ this -> setContextMainMenu ( $ mainMenuItemCode ) ; $ this -> setContextSideMenu ( $ sideMenuItemCode ) ; }
Sets the navigation context . The function sets the navigation owner main menu item code and the side menu item code .
23,441
public function isMainMenuItemActive ( $ item ) { return $ this -> contextOwner == $ item -> owner && $ this -> contextMainMenuItemCode == $ item -> code ; }
Determines if a main menu item is active .
23,442
public function getActiveMainMenuItem ( ) { foreach ( $ this -> listMainMenuItems ( ) as $ item ) { if ( $ this -> isMainMenuItemActive ( $ item ) ) { return $ item ; } } return null ; }
Returns the currently active main menu item
23,443
public function isSideMenuItemActive ( $ item ) { if ( $ this -> contextSideMenuItemCode === true ) { $ this -> contextSideMenuItemCode = null ; return true ; } return $ this -> contextOwner == $ item -> owner && $ this -> contextSideMenuItemCode == $ item -> code ; }
Determines if a side menu item is active .
23,444
protected function filterItemPermissions ( $ user , array $ items ) { if ( ! $ user ) { return $ items ; } $ items = array_filter ( $ items , function ( $ item ) use ( $ user ) { if ( ! $ item -> permissions || ! count ( $ item -> permissions ) ) { return true ; } return $ user -> hasAnyAccess ( $ item -> permissions )...
Removes menu items from an array if the supplied user lacks permission .
23,445
public function getTokenParsers ( ) { return [ new PageTokenParser , new PartialTokenParser , new ContentTokenParser , new PutTokenParser , new PlaceholderTokenParser , new DefaultTokenParser , new FrameworkTokenParser , new ComponentTokenParser , new FlashTokenParser , new ScriptsTokenParser , new StylesTokenParser , ...
Returns a list of token parsers this extensions provides .
23,446
public function placeholderFunction ( $ name , $ default = null ) { if ( ( $ result = Block :: get ( $ name ) ) === null ) { return null ; } $ result = str_replace ( '<!-- X_OCTOBER_DEFAULT_BLOCK_CONTENT , trim ( $ default ) , $ result ) ; return $ result ; }
Renders a placeholder content without removing the block must be called before the placeholder tag itself
23,447
public function displayBlock ( $ name , $ default = null ) { if ( ( $ result = Block :: placeholder ( $ name ) ) === null ) { return $ default ; } if ( $ event = Event :: fire ( 'cms.block.render' , [ $ name , $ result ] , true ) ) $ result = $ event ; $ result = str_replace ( '<!-- X_OCTOBER_DEFAULT_BLOCK_CONTENT , t...
Returns a layout block contents and removes the block .
23,448
public function processCompoundObject ( Exception $ exception ) { switch ( $ this -> code ) { case 200 : $ result = $ this -> processIni ( $ exception ) ; break ; case 300 : $ result = $ this -> processPhp ( $ exception ) ; break ; case 400 : $ result = $ this -> processTwig ( $ exception ) ; break ; } if ( $ result !=...
Checks some conditions to confirm error has actually occurred due to the CMS template code not some external code . If the error has occurred in external code the function will return false . Otherwise return true and modify the exception by overriding it s content line and message values to be accurate against a CMS o...
23,449
protected function processIni ( Exception $ exception ) { $ message = $ exception -> getMessage ( ) ; if ( ! starts_with ( $ message , 'syntax error' ) ) { return false ; } if ( strpos ( $ message , 'Unknown' ) === false ) { return false ; } if ( strpos ( $ exception -> getFile ( ) , 'Ini.php' ) === false ) { return fa...
Override properties of an exception specific to the INI section of a CMS object .
23,450
protected function processPhp ( Exception $ exception ) { if ( $ exception instanceof \ Symfony \ Component \ Debug \ Exception \ FatalErrorException ) { $ check = false ; if ( strpos ( $ exception -> getFile ( ) , 'CodeParser.php' ) ) { $ check = true ; } if ( strpos ( $ exception -> getFile ( ) , $ this -> compoundOb...
Override properties of an exception specific to the PHP section of a CMS object .
23,451
protected function processTwig ( Exception $ exception ) { if ( ! $ exception instanceof Twig_Error ) { return false ; } $ this -> message = $ exception -> getRawMessage ( ) ; $ this -> line = $ exception -> getTemplateLine ( ) ; $ offsetArray = SectionParser :: parseOffset ( $ this -> compoundObject -> getContent ( ) ...
Override properties of an exception specific to the Twig section of a CMS object .
23,452
public function validateProperties ( array $ properties ) { $ definedProperties = $ this -> defineProperties ( ) ? : [ ] ; $ defaultProperties = [ ] ; foreach ( $ definedProperties as $ name => $ information ) { if ( array_key_exists ( 'default' , $ information ) ) { $ defaultProperties [ $ name ] = $ information [ 'de...
Validates the properties against the defined properties of the class . This method also sets default properties .
23,453
public function formExtendQuery ( $ query ) { if ( ! $ this -> user -> isSuperUser ( ) ) { $ query -> where ( 'is_superuser' , false ) ; } $ query -> withTrashed ( ) ; }
Extends the form query to prevent non - superusers from accessing superusers at all
23,454
public function update_onRestore ( $ recordId ) { $ this -> formFindModelObject ( $ recordId ) -> restore ( ) ; Flash :: success ( Lang :: get ( 'backend::lang.form.restore_success' , [ 'name' => Lang :: get ( 'backend::lang.user.name' ) ] ) ) ; return Redirect :: refresh ( ) ; }
Handle restoring users
23,455
public function myaccount ( ) { SettingsManager :: setContext ( 'October.Backend' , 'myaccount' ) ; $ this -> pageTitle = 'backend::lang.myaccount.menu_label' ; return $ this -> update ( $ this -> user -> id , 'myaccount' ) ; }
My Settings controller
23,456
public function myaccount_onSave ( ) { $ result = $ this -> asExtension ( 'FormController' ) -> update_onSave ( $ this -> user -> id , 'myaccount' ) ; $ loginChanged = $ this -> user -> login != post ( 'User[login]' ) ; $ passwordChanged = strlen ( post ( 'User[password]' ) ) ; if ( $ loginChanged || $ passwordChanged ...
Proxy update onSave event
23,457
public function formExtendFields ( $ form ) { if ( $ form -> getContext ( ) == 'myaccount' ) { return ; } if ( ! $ this -> user -> isSuperUser ( ) ) { $ form -> removeField ( 'is_superuser' ) ; } $ form -> addTabFields ( $ this -> generatePermissionsField ( ) ) ; if ( ! $ form -> model -> exists ) { $ defaultGroupIds =...
Add available permission fields to the User form . Mark default groups as checked for new Users .
23,458
public function setInstalled ( $ code , $ dirName = null ) { if ( ! $ dirName ) { $ dirName = strtolower ( str_replace ( '.' , '-' , $ code ) ) ; } $ history = Parameter :: get ( 'system::theme.history' , [ ] ) ; $ history [ $ code ] = $ dirName ; Parameter :: set ( 'system::theme.history' , $ history ) ; }
Flags a theme as being installed so it is not downloaded twice .
23,459
public function setUninstalled ( $ code ) { $ history = Parameter :: get ( 'system::theme.history' , [ ] ) ; if ( array_key_exists ( $ code , $ history ) ) { unset ( $ history [ $ code ] ) ; } Parameter :: set ( 'system::theme.history' , $ history ) ; }
Flags a theme as being uninstalled .
23,460
public function findByDirName ( $ dirName ) { $ installed = $ this -> getInstalled ( ) ; foreach ( $ installed as $ code => $ name ) { if ( $ dirName == $ name ) { return $ code ; } } return null ; }
Returns an installed theme s code from it s dirname .
23,461
public function deleteTheme ( $ theme ) { if ( ! $ theme ) { return false ; } if ( is_string ( $ theme ) ) { $ theme = CmsTheme :: load ( $ theme ) ; } if ( $ theme -> isActiveTheme ( ) ) { throw new ApplicationException ( trans ( 'cms::lang.theme.delete_active_theme_failed' ) ) ; } $ themePath = $ theme -> getPath ( )...
Completely delete a theme from the system .
23,462
public static function initFallback ( $ theme ) { $ obj = self :: inTheme ( $ theme ) ; $ obj -> markup = '{% page %}' ; $ obj -> fileName = self :: FALLBACK_FILE_NAME ; return $ obj ; }
Initializes the fallback layout .
23,463
protected function passToCmsController ( $ url ) { if ( class_exists ( '\Cms\Classes\Controller' ) ) { return App :: make ( 'Cms\Classes\Controller' ) -> run ( $ url ) ; } else { return Response :: make ( View :: make ( 'backend::404' ) , 404 ) ; } }
Pass unhandled URLs to the CMS Controller if it exists
23,464
protected function findController ( $ controller , $ action , $ inPath ) { if ( ! class_exists ( $ controller ) ) { $ controller = Str :: normalizeClassName ( $ controller ) ; $ controllerFile = $ inPath . strtolower ( str_replace ( '\\' , '/' , $ controller ) ) . '.php' ; if ( $ controllerFile = File :: existsInsensit...
This method is used internally . Finds a backend controller with a callable action method .
23,465
public static function bindEventsToModel ( HalcyonModel $ template ) { $ template -> bindEvent ( 'model.beforeDelete' , function ( ) use ( $ template ) { self :: add ( $ template , self :: TYPE_DELETE ) ; } ) ; $ template -> bindEvent ( 'model.beforeSave' , function ( ) use ( $ template ) { self :: add ( $ template , $...
Adds observers to the model for logging purposes .
23,466
protected function prepareModelsToSave ( $ model , $ saveData ) { $ this -> modelsToSave = [ ] ; $ this -> setModelAttributes ( $ model , $ saveData ) ; $ this -> modelsToSave = array_reverse ( $ this -> modelsToSave ) ; return $ this -> modelsToSave ; }
Takes a model and fills it with data from a multidimensional array . If an attribute is found to be a relationship that relationship is also filled .
23,467
protected function setModelAttributes ( $ model , $ saveData ) { $ this -> modelsToSave [ ] = $ model ; if ( ! is_array ( $ saveData ) ) { return ; } if ( $ model instanceof HalcyonModel ) { $ model -> fill ( $ saveData ) ; return ; } $ attributesToPurge = [ ] ; $ singularTypes = [ 'belongsTo' , 'hasOne' , 'morphTo' , ...
Sets a data collection to a model attributes relations are also set .
23,468
protected function deferPurgedSaveAttributes ( $ model , $ attributesToPurge ) { if ( ! is_array ( $ attributesToPurge ) ) { return ; } if ( method_exists ( $ model , 'getPurgeableAttributes' ) ) { $ model -> addPurgeable ( $ attributesToPurge ) ; } else { $ model -> bindEventOnce ( 'model.saveInternal' , function ( ) ...
Removes an array of attributes from the model . If the model implements the Purgeable trait this is preferred over the internal logic .
23,469
public function options ( $ value = null ) { if ( $ value === null ) { if ( is_array ( $ this -> options ) ) { return $ this -> options ; } elseif ( is_callable ( $ this -> options ) ) { $ callable = $ this -> options ; return $ callable ( ) ; } return [ ] ; } $ this -> options = $ value ; return $ this ; }
Sets field options for dropdowns radio lists and checkbox lists .
23,470
public function comment ( $ text , $ position = 'below' , $ isHtml = null ) { $ this -> comment = $ text ; $ this -> commentPosition = $ position ; if ( $ isHtml !== null ) { $ this -> commentHtml = $ isHtml ; } return $ this ; }
Adds a text comment above or below the field .
23,471
public function isSelected ( $ value = true ) { if ( $ this -> value === null ) { return false ; } return ( string ) $ value === ( string ) $ this -> value ; }
Determine if the provided value matches this field s value .
23,472
public function getAttributes ( $ position = 'field' , $ htmlBuild = true ) { $ result = array_get ( $ this -> attributes , $ position , [ ] ) ; $ result = $ this -> filterAttributes ( $ result , $ position ) ; return $ htmlBuild ? Html :: attributes ( $ result ) : $ result ; }
Returns the attributes for this field at a given position .
23,473
protected function filterAttributes ( $ attributes , $ position = 'field' ) { $ position = strtolower ( $ position ) ; $ attributes = $ this -> filterTriggerAttributes ( $ attributes , $ position ) ; $ attributes = $ this -> filterPresetAttributes ( $ attributes , $ position ) ; if ( $ position == 'field' && $ this -> ...
Adds any circumstantial attributes to the field based on other settings such as the disabled option .
23,474
protected function filterTriggerAttributes ( $ attributes , $ position = 'field' ) { if ( ! $ this -> trigger || ! is_array ( $ this -> trigger ) ) { return $ attributes ; } $ triggerAction = array_get ( $ this -> trigger , 'action' ) ; $ triggerField = array_get ( $ this -> trigger , 'field' ) ; $ triggerCondition = a...
Adds attributes used specifically by the Trigger API
23,475
protected function filterPresetAttributes ( $ attributes , $ position = 'field' ) { if ( ! $ this -> preset || $ position != 'field' ) { return $ attributes ; } if ( ! is_array ( $ this -> preset ) ) { $ this -> preset = [ 'field' => $ this -> preset , 'type' => 'slug' ] ; } $ presetField = array_get ( $ this -> preset...
Adds attributes used specifically by the Input Preset API
23,476
public function getName ( $ arrayName = null ) { if ( $ arrayName === null ) { $ arrayName = $ this -> arrayName ; } if ( $ arrayName ) { return $ arrayName . '[' . implode ( '][' , HtmlHelper :: nameToArray ( $ this -> fieldName ) ) . ']' ; } return $ this -> fieldName ; }
Returns a value suitable for the field name property .
23,477
public function getId ( $ suffix = null ) { $ id = 'field' ; if ( $ this -> arrayName ) { $ id .= '-' . $ this -> arrayName ; } $ id .= '-' . $ this -> fieldName ; if ( $ suffix ) { $ id .= '-' . $ suffix ; } if ( $ this -> idPrefix ) { $ id = $ this -> idPrefix . '-' . $ id ; } return HtmlHelper :: nameToId ( $ id ) ;...
Returns a value suitable for the field id property .
23,478
public function getValueFromData ( $ data , $ default = null ) { $ fieldName = $ this -> valueFrom ? : $ this -> fieldName ; return $ this -> getFieldNameFromData ( $ fieldName , $ data , $ default ) ; }
Returns this fields value from a supplied data set which can be an array or a model or another generic collection .
23,479
public function getDefaultFromData ( $ data ) { if ( $ this -> defaultFrom ) { return $ this -> getFieldNameFromData ( $ this -> defaultFrom , $ data ) ; } if ( $ this -> defaults !== '' ) { return $ this -> defaults ; } return null ; }
Returns the default value for this field the supplied data is used to source data when defaultFrom is specified .
23,480
protected function getFieldNameFromData ( $ fieldName , $ data , $ default = null ) { $ keyParts = HtmlHelper :: nameToArray ( $ fieldName ) ; $ lastField = end ( $ keyParts ) ; $ result = $ data ; foreach ( $ keyParts as $ key ) { if ( $ result instanceof Model && $ result -> hasRelation ( $ key ) ) { if ( $ key == $ ...
Internal method to extract the value of a field name from a data set .
23,481
public function listPermissions ( ) { if ( $ this -> permissionCache !== false ) { return $ this -> permissionCache ; } foreach ( $ this -> callbacks as $ callback ) { $ callback ( $ this ) ; } $ plugins = PluginManager :: instance ( ) -> getPlugins ( ) ; foreach ( $ plugins as $ id => $ plugin ) { $ items = $ plugin -...
Returns a list of the registered permissions items .
23,482
public function listTabbedPermissions ( ) { $ tabs = [ ] ; foreach ( $ this -> listPermissions ( ) as $ permission ) { $ tab = $ permission -> tab ?? 'backend::lang.form.undefined_tab' ; if ( ! array_key_exists ( $ tab , $ tabs ) ) { $ tabs [ $ tab ] = [ ] ; } $ tabs [ $ tab ] [ ] = $ permission ; } return $ tabs ; }
Returns an array of registered permissions grouped by tabs .
23,483
public function listPermissionsForRole ( $ role , $ includeOrphans = true ) { if ( $ this -> permissionRoles === false ) { $ this -> permissionRoles = [ ] ; foreach ( $ this -> listPermissions ( ) as $ permission ) { if ( $ permission -> roles ) { foreach ( ( array ) $ permission -> roles as $ _role ) { $ this -> permi...
Returns an array of registered permissions belonging to a given role code
23,484
public function getId ( $ suffix = null ) { $ id = 'scope' ; $ id .= '-' . $ this -> scopeName ; if ( $ suffix ) { $ id .= '-' . $ suffix ; } if ( $ this -> idPrefix ) { $ id = $ this -> idPrefix . '-' . $ id ; } return HtmlHelper :: nameToId ( $ id ) ; }
Returns a value suitable for the scope id property .
23,485
public function addField ( $ name , FormField $ field , $ tab = null ) { if ( ! $ tab ) { $ tab = $ this -> defaultTab ; } $ this -> fields [ $ tab ] [ $ name ] = $ field ; }
Add a field to the collection of tabs .
23,486
public function removeField ( $ name ) { foreach ( $ this -> fields as $ tab => $ fields ) { foreach ( $ fields as $ fieldName => $ field ) { if ( $ fieldName == $ name ) { unset ( $ this -> fields [ $ tab ] [ $ fieldName ] ) ; if ( ! count ( $ this -> fields [ $ tab ] ) ) { unset ( $ this -> fields [ $ tab ] ) ; } ret...
Remove a field from all tabs by name .
23,487
public function getPaneCssClass ( $ index = null , $ label = null ) { if ( is_string ( $ this -> paneCssClass ) ) { return $ this -> paneCssClass ; } if ( $ index !== null && isset ( $ this -> paneCssClass [ $ index ] ) ) { return $ this -> paneCssClass [ $ index ] ; } if ( $ label !== null && isset ( $ this -> paneCss...
Returns a tab pane CSS class .
23,488
public function renderField ( $ field , $ options = [ ] ) { $ this -> prepareVars ( ) ; if ( is_string ( $ field ) ) { if ( ! isset ( $ this -> allFields [ $ field ] ) ) { throw new ApplicationException ( Lang :: get ( 'backend::lang.form.missing_definition' , compact ( 'field' ) ) ) ; } $ field = $ this -> allFields [...
Renders a single form field
23,489
protected function prepareVars ( ) { $ this -> defineFormFields ( ) ; $ this -> applyFiltersFromModel ( ) ; $ this -> vars [ 'sessionKey' ] = $ this -> getSessionKey ( ) ; $ this -> vars [ 'outsideTabs' ] = $ this -> allTabs -> outside ; $ this -> vars [ 'primaryTabs' ] = $ this -> allTabs -> primary ; $ this -> vars [...
Prepares the form data
23,490
public function setFormValues ( $ data = null ) { if ( $ data === null ) { $ data = $ this -> getSaveData ( ) ; } $ this -> prepareModelsToSave ( $ this -> model , $ data ) ; if ( $ this -> data !== $ this -> model ) { $ this -> data = ( object ) array_merge ( ( array ) $ this -> data , ( array ) $ data ) ; } foreach (...
Sets or resets form field values .
23,491
public function onRefresh ( ) { $ result = [ ] ; $ saveData = $ this -> getSaveData ( ) ; $ dataHolder = ( object ) [ 'data' => $ saveData ] ; $ this -> fireSystemEvent ( 'backend.form.beforeRefresh' , [ $ dataHolder ] ) ; $ saveData = $ dataHolder -> data ; $ this -> setFormValues ( $ saveData ) ; $ this -> prepareVar...
Event handler for refreshing the form .
23,492
protected function defineFormFields ( ) { if ( $ this -> fieldsDefined ) { return ; } $ this -> fireSystemEvent ( 'backend.form.extendFieldsBefore' ) ; if ( ! isset ( $ this -> fields ) || ! is_array ( $ this -> fields ) ) { $ this -> fields = [ ] ; } $ this -> allTabs -> outside = new FormTabs ( FormTabs :: SECTION_OU...
Creates a flat array of form fields from the configuration . Also slots fields in to their respective tabs .
23,493
protected function processAutoSpan ( $ fields ) { $ prevSpan = null ; foreach ( $ fields as $ field ) { if ( strtolower ( $ field -> span ) === 'auto' ) { if ( $ prevSpan === 'left' ) { $ field -> span = 'right' ; } else { $ field -> span = 'left' ; } } $ prevSpan = $ field -> span ; } }
Converts fields with a span set to auto as either left or right depending on the previous field .
23,494
public function addFields ( array $ fields , $ addToArea = null ) { foreach ( $ fields as $ name => $ config ) { $ fieldObj = $ this -> makeFormField ( $ name , $ config ) ; $ fieldTab = is_array ( $ config ) ? array_get ( $ config , 'tab' ) : null ; if ( $ fieldObj -> context !== null ) { $ context = is_array ( $ fiel...
Programatically add fields used internally and for extensibility .
23,495
public function removeField ( $ name ) { if ( ! isset ( $ this -> allFields [ $ name ] ) ) { return false ; } $ this -> allTabs -> primary -> removeField ( $ name ) ; $ this -> allTabs -> secondary -> removeField ( $ name ) ; $ this -> allTabs -> outside -> removeField ( $ name ) ; unset ( $ this -> allFields [ $ name ...
Programatically remove a field .
23,496
public function removeTab ( $ name ) { foreach ( $ this -> allFields as $ fieldName => $ field ) { if ( $ field -> tab == $ name ) { $ this -> removeField ( $ fieldName ) ; } } }
Programatically remove all fields belonging to a tab .
23,497
protected function makeFormField ( $ name , $ config = [ ] ) { $ label = $ config [ 'label' ] ?? null ; list ( $ fieldName , $ fieldContext ) = $ this -> getFieldName ( $ name ) ; $ field = new FormField ( $ fieldName , $ label ) ; if ( $ fieldContext ) { $ field -> context = $ fieldContext ; } $ field -> arrayName = $...
Creates a form field object from name and configuration .
23,498
protected function isFormWidget ( $ fieldType ) { if ( $ fieldType === null ) { return false ; } if ( strpos ( $ fieldType , '\\' ) ) { return true ; } $ widgetClass = $ this -> widgetManager -> resolveFormWidget ( $ fieldType ) ; if ( ! class_exists ( $ widgetClass ) ) { return false ; } if ( is_subclass_of ( $ widget...
Check if a field type is a widget or not
23,499
protected function makeFormFieldWidget ( $ field ) { if ( $ field -> type !== 'widget' ) { return null ; } if ( isset ( $ this -> formWidgets [ $ field -> fieldName ] ) ) { return $ this -> formWidgets [ $ field -> fieldName ] ; } $ widgetConfig = $ this -> makeConfig ( $ field -> config ) ; $ widgetConfig -> alias = $...
Makes a widget object from a form field object .