idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
8,200
public function limitImageSize ( $ width , $ height ) { if ( $ this -> maxImageSize !== null ) { $ imageSize = $ width * $ height ; if ( $ imageSize > $ this -> maxImageSize ) { $ width = $ width / sqrt ( $ imageSize / $ this -> maxImageSize ) ; $ height = $ height / sqrt ( $ imageSize / $ this -> maxImageSize ) ; } } ...
Limit image size to maximum allowed image size .
8,201
public function runResize ( Image $ image , $ fit , $ width , $ height ) { if ( $ fit === 'contain' ) { return $ this -> runContainResize ( $ image , $ width , $ height ) ; } if ( $ fit === 'fill' ) { return $ this -> runFillResize ( $ image , $ width , $ height ) ; } if ( $ fit === 'max' ) { return $ this -> runMaxRes...
Perform resize image manipulation .
8,202
public function runContainResize ( Image $ image , $ width , $ height ) { return $ image -> resize ( $ width , $ height , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) ; }
Perform contain resize image manipulation .
8,203
public function runMaxResize ( Image $ image , $ width , $ height ) { return $ image -> resize ( $ width , $ height , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; $ constraint -> upsize ( ) ; } ) ; }
Perform max resize image manipulation .
8,204
public function runFillResize ( $ image , $ width , $ height ) { $ image = $ this -> runMaxResize ( $ image , $ width , $ height ) ; return $ image -> resizeCanvas ( $ width , $ height , 'center' ) ; }
Perform fill resize image manipulation .
8,205
public function runCropResize ( Image $ image , $ width , $ height ) { list ( $ resize_width , $ resize_height ) = $ this -> resolveCropResizeDimensions ( $ image , $ width , $ height ) ; $ zoom = $ this -> getCrop ( ) [ 2 ] ; $ image -> resize ( $ resize_width * $ zoom , $ resize_height * $ zoom , function ( $ constra...
Perform crop resize image manipulation .
8,206
public function resolveCropResizeDimensions ( Image $ image , $ width , $ height ) { if ( $ height > $ width * ( $ image -> height ( ) / $ image -> width ( ) ) ) { return [ $ height * ( $ image -> width ( ) / $ image -> height ( ) ) , $ height ] ; } return [ $ width , $ width * ( $ image -> height ( ) / $ image -> widt...
Resolve the crop resize dimensions .
8,207
public function resolveCropOffset ( Image $ image , $ width , $ height ) { list ( $ offset_percentage_x , $ offset_percentage_y ) = $ this -> getCrop ( ) ; $ offset_x = ( int ) ( ( $ image -> width ( ) * $ offset_percentage_x / 100 ) - ( $ width / 2 ) ) ; $ offset_y = ( int ) ( ( $ image -> height ( ) * $ offset_percen...
Resolve the crop offset .
8,208
public function getCrop ( ) { $ cropMethods = [ 'crop-top-left' => [ 0 , 0 , 1.0 ] , 'crop-top' => [ 50 , 0 , 1.0 ] , 'crop-top-right' => [ 100 , 0 , 1.0 ] , 'crop-left' => [ 0 , 50 , 1.0 ] , 'crop-center' => [ 50 , 50 , 1.0 ] , 'crop-right' => [ 100 , 50 , 1.0 ] , 'crop-bottom-left' => [ 0 , 100 , 1.0 ] , 'crop-bottom...
Resolve crop with zoom .
8,209
public function run ( Image $ image ) { $ pixelate = $ this -> getPixelate ( ) ; if ( $ pixelate !== null ) { $ image -> pixelate ( $ pixelate ) ; } return $ image ; }
Perform pixelate image manipulation .
8,210
public function getPixelate ( ) { if ( ! is_numeric ( $ this -> pixel ) ) { return ; } if ( $ this -> pixel < 0 or $ this -> pixel > 1000 ) { return ; } return ( int ) $ this -> pixel ; }
Resolve pixelate amount .
8,211
public function get ( $ value ) { if ( is_numeric ( $ value ) and $ value > 0 ) { return ( double ) $ value * $ this -> dpr ; } if ( preg_match ( '/^(\d{1,2}(?!\d)|100)(w|h)$/' , $ value , $ matches ) ) { if ( $ matches [ 2 ] === 'h' ) { return ( double ) $ this -> image -> height ( ) * ( $ matches [ 1 ] / 100 ) ; } re...
Resolve the dimension .
8,212
public function run ( Image $ image ) { if ( $ flip = $ this -> getFlip ( ) ) { if ( $ flip === 'both' ) { return $ image -> flip ( 'h' ) -> flip ( 'v' ) ; } return $ image -> flip ( $ flip ) ; } return $ image ; }
Perform flip image manipulation .
8,213
public function run ( Image $ image ) { $ brightness = $ this -> getBrightness ( ) ; if ( $ brightness !== null ) { $ image -> brightness ( $ brightness ) ; } return $ image ; }
Perform brightness image manipulation .
8,214
public function getBrightness ( ) { if ( ! preg_match ( '/^-*[0-9]+$/' , $ this -> bri ) ) { return ; } if ( $ this -> bri < - 100 or $ this -> bri > 100 ) { return ; } return ( int ) $ this -> bri ; }
Resolve brightness amount .
8,215
public function setManipulators ( array $ manipulators ) { foreach ( $ manipulators as $ manipulator ) { if ( ! ( $ manipulator instanceof ManipulatorInterface ) ) { throw new InvalidArgumentException ( 'Not a valid manipulator.' ) ; } } $ this -> manipulators = $ manipulators ; }
Set the manipulators .
8,216
public function run ( $ source , array $ params ) { $ image = $ this -> imageManager -> make ( $ source ) ; foreach ( $ this -> manipulators as $ manipulator ) { $ manipulator -> setParams ( $ params ) ; $ image = $ manipulator -> run ( $ image ) ; } return $ image -> getEncoded ( ) ; }
Perform image manipulations .
8,217
public function run ( Image $ image ) { if ( is_null ( $ this -> bg ) ) { return $ image ; } $ color = ( new Color ( $ this -> bg ) ) -> formatted ( ) ; if ( $ color ) { $ new = $ image -> getDriver ( ) -> newImage ( $ image -> width ( ) , $ image -> height ( ) , $ color ) ; $ new -> mime = $ image -> mime ; $ image = ...
Perform background image manipulation .
8,218
public function run ( Image $ image ) { $ gamma = $ this -> getGamma ( ) ; if ( $ gamma ) { $ image -> gamma ( $ gamma ) ; } return $ image ; }
Perform gamma image manipulation .
8,219
public function getGamma ( ) { if ( ! preg_match ( '/^[0-9]\.*[0-9]*$/' , $ this -> gam ) ) { return ; } if ( $ this -> gam < 0.1 or $ this -> gam > 9.99 ) { return ; } return ( double ) $ this -> gam ; }
Resolve gamma amount .
8,220
public static function create ( $ baseUrl , $ signKey = null ) { $ httpSignature = null ; if ( ! is_null ( $ signKey ) ) { $ httpSignature = SignatureFactory :: create ( $ signKey ) ; } return new UrlBuilder ( $ baseUrl , $ httpSignature ) ; }
Create UrlBuilder instance .
8,221
public function run ( Image $ image ) { if ( $ watermark = $ this -> getImage ( $ image ) ) { $ markw = $ this -> getDimension ( $ image , 'markw' ) ; $ markh = $ this -> getDimension ( $ image , 'markh' ) ; $ markx = $ this -> getDimension ( $ image , 'markx' ) ; $ marky = $ this -> getDimension ( $ image , 'marky' ) ...
Perform watermark image manipulation .
8,222
public function getImage ( Image $ image ) { if ( is_null ( $ this -> watermarks ) ) { return ; } if ( ! is_string ( $ this -> mark ) ) { return ; } if ( $ this -> mark === '' ) { return ; } $ path = $ this -> mark ; if ( $ this -> watermarksPathPrefix ) { $ path = $ this -> watermarksPathPrefix . '/' . $ path ; } if (...
Get the watermark image .
8,223
public function getDimension ( Image $ image , $ field ) { if ( $ this -> { $ field } ) { return ( new Dimension ( $ image , $ this -> getDpr ( ) ) ) -> get ( $ this -> { $ field } ) ; } }
Get a dimension .
8,224
public function getAlpha ( ) { if ( ! is_numeric ( $ this -> markalpha ) ) { return 100 ; } if ( $ this -> markalpha < 0 or $ this -> markalpha > 100 ) { return 100 ; } return ( int ) $ this -> markalpha ; }
Get the alpha channel .
8,225
public function getSourcePath ( $ path ) { $ path = trim ( $ path , '/' ) ; $ baseUrl = $ this -> baseUrl . '/' ; if ( substr ( $ path , 0 , strlen ( $ baseUrl ) ) === $ baseUrl ) { $ path = trim ( substr ( $ path , strlen ( $ baseUrl ) ) , '/' ) ; } if ( $ path === '' ) { throw new FileNotFoundException ( 'Image path ...
Get source path .
8,226
public function getCachePath ( $ path , array $ params = [ ] ) { $ sourcePath = $ this -> getSourcePath ( $ path ) ; if ( $ this -> sourcePathPrefix ) { $ sourcePath = substr ( $ sourcePath , strlen ( $ this -> sourcePathPrefix ) + 1 ) ; } $ params = $ this -> getAllParams ( $ params ) ; unset ( $ params [ 's' ] , $ pa...
Get cache path .
8,227
public function cacheFileExists ( $ path , array $ params ) { return $ this -> cache -> has ( $ this -> getCachePath ( $ path , $ params ) ) ; }
Check if a cache file exists .
8,228
public function deleteCache ( $ path ) { if ( ! $ this -> groupCacheInFolders ) { throw new InvalidArgumentException ( 'Deleting cached image manipulations is not possible when grouping cache into folders is disabled.' ) ; } return $ this -> cache -> deleteDir ( dirname ( $ this -> getCachePath ( $ path ) ) ) ; }
Delete cached manipulations for an image .
8,229
public function getAllParams ( array $ params ) { $ all = $ this -> defaults ; if ( isset ( $ params [ 'p' ] ) ) { foreach ( explode ( ',' , $ params [ 'p' ] ) as $ preset ) { if ( isset ( $ this -> presets [ $ preset ] ) ) { $ all = array_merge ( $ all , $ this -> presets [ $ preset ] ) ; } } } return array_merge ( $ ...
Get all image manipulations params including defaults and presets .
8,230
public function makeImage ( $ path , array $ params ) { $ sourcePath = $ this -> getSourcePath ( $ path ) ; $ cachedPath = $ this -> getCachePath ( $ path , $ params ) ; if ( $ this -> cacheFileExists ( $ path , $ params ) === true ) { return $ cachedPath ; } if ( $ this -> sourceFileExists ( $ path ) === false ) { thr...
Generate manipulated image .
8,231
public function run ( Image $ image ) { if ( $ border = $ this -> getBorder ( $ image ) ) { list ( $ width , $ color , $ method ) = $ border ; if ( $ method === 'overlay' ) { return $ this -> runOverlay ( $ image , $ width , $ color ) ; } if ( $ method === 'shrink' ) { return $ this -> runShrink ( $ image , $ width , $...
Perform border image manipulation .
8,232
public function getBorder ( Image $ image ) { if ( ! $ this -> border ) { return ; } $ values = explode ( ',' , $ this -> border ) ; $ width = $ this -> getWidth ( $ image , $ this -> getDpr ( ) , isset ( $ values [ 0 ] ) ? $ values [ 0 ] : null ) ; $ color = $ this -> getColor ( isset ( $ values [ 1 ] ) ? $ values [ 1...
Resolve border amount .
8,233
public function getWidth ( Image $ image , $ dpr , $ width ) { return ( new Dimension ( $ image , $ dpr ) ) -> get ( $ width ) ; }
Get border width .
8,234
public function runOverlay ( Image $ image , $ width , $ color ) { return $ image -> rectangle ( $ width / 2 , $ width / 2 , $ image -> width ( ) - ( $ width / 2 ) , $ image -> height ( ) - ( $ width / 2 ) , function ( $ draw ) use ( $ width , $ color ) { $ draw -> border ( $ width , $ color ) ; } ) ; }
Run the overlay border method .
8,235
public function runShrink ( Image $ image , $ width , $ color ) { return $ image -> resize ( $ image -> width ( ) - ( $ width * 2 ) , $ image -> height ( ) - ( $ width * 2 ) ) -> resizeCanvas ( $ width * 2 , $ width * 2 , 'center' , true , $ color ) ; }
Run the shrink border method .
8,236
public function runExpand ( Image $ image , $ width , $ color ) { return $ image -> resizeCanvas ( $ width * 2 , $ width * 2 , 'center' , true , $ color ) ; }
Run the expand border method .
8,237
public function setBaseUrl ( $ baseUrl ) { if ( substr ( $ baseUrl , 0 , 2 ) === '//' ) { $ baseUrl = 'http:' . $ baseUrl ; $ this -> isRelativeDomain = true ; } $ this -> baseUrl = rtrim ( $ baseUrl , '/' ) ; }
Set the base URL .
8,238
public function createSidebarMenu ( ) { $ menu = $ this -> factory -> createItem ( 'root' ) ; foreach ( $ this -> pool -> getAdminGroups ( ) as $ name => $ group ) { $ extras = [ 'icon' => $ group [ 'icon' ] , 'label_catalogue' => $ group [ 'label_catalogue' ] , 'roles' => $ group [ 'roles' ] , 'sonata_admin' => true ,...
Builds sidebar menu .
8,239
public function ifTrue ( $ bool ) { if ( null !== $ this -> apply ) { throw new \ RuntimeException ( 'Cannot nest ifTrue or ifFalse call' ) ; } $ this -> apply = ( true === $ bool ) ; return $ this ; }
Only nested add if the condition match true .
8,240
public function ifFalse ( $ bool ) { if ( null !== $ this -> apply ) { throw new \ RuntimeException ( 'Cannot nest ifTrue or ifFalse call' ) ; } $ this -> apply = ( false === $ bool ) ; return $ this ; }
Only nested add if the condition match false .
8,241
public function end ( ) { if ( null !== $ this -> currentGroup ) { $ this -> currentGroup = null ; } elseif ( null !== $ this -> currentTab ) { $ this -> currentTab = null ; } else { throw new \ RuntimeException ( 'No open tabs or groups, you cannot use end()' ) ; } return $ this ; }
Close the current group or tab .
8,242
protected function addFieldToCurrentGroup ( $ fieldName ) { $ currentGroup = $ this -> getCurrentGroupName ( ) ; $ groups = $ this -> getGroups ( ) ; $ groups [ $ currentGroup ] [ 'fields' ] [ $ fieldName ] = $ fieldName ; $ this -> setGroups ( $ groups ) ; return $ groups [ $ currentGroup ] ; }
Add the field name to the current group .
8,243
protected function getCurrentGroupName ( ) { if ( ! $ this -> currentGroup ) { $ this -> with ( $ this -> admin -> getLabel ( ) , [ 'auto_created' => true ] ) ; } return $ this -> currentGroup ; }
Return the name of the currently selected group . The method also makes sure a valid group name is currently selected .
8,244
private function legacyConstructor ( array $ args ) { $ choiceList = $ args [ 0 ] ; if ( ! $ choiceList instanceof ModelChoiceList && ! $ choiceList instanceof ModelChoiceLoader && ! $ choiceList instanceof LazyChoiceList ) { throw new RuntimeException ( 'First param passed to ModelsToArrayTransformer should be instanc...
Simulates the old constructor for BC .
8,245
public function createAclUsersForm ( AdminObjectAclData $ data ) { $ aclValues = $ data -> getAclUsers ( ) ; $ formBuilder = $ this -> formFactory -> createNamedBuilder ( self :: ACL_USERS_FORM_NAME , FormType :: class ) ; $ form = $ this -> buildForm ( $ data , $ formBuilder , $ aclValues ) ; $ data -> setAclUsersForm...
Gets the ACL users form .
8,246
public function createAclRolesForm ( AdminObjectAclData $ data ) { $ aclValues = $ data -> getAclRoles ( ) ; $ formBuilder = $ this -> formFactory -> createNamedBuilder ( self :: ACL_ROLES_FORM_NAME , FormType :: class ) ; $ form = $ this -> buildForm ( $ data , $ formBuilder , $ aclValues ) ; $ data -> setAclRolesForm...
Gets the ACL roles form .
8,247
public function updateAclUsers ( AdminObjectAclData $ data ) { $ aclValues = $ data -> getAclUsers ( ) ; $ form = $ data -> getAclUsersForm ( ) ; $ this -> buildAcl ( $ data , $ form , $ aclValues ) ; }
Updates ACL users .
8,248
public function updateAclRoles ( AdminObjectAclData $ data ) { $ aclValues = $ data -> getAclRoles ( ) ; $ form = $ data -> getAclRolesForm ( ) ; $ this -> buildAcl ( $ data , $ form , $ aclValues ) ; }
Updates ACL roles .
8,249
protected function buildAcl ( AdminObjectAclData $ data , Form $ form , \ Traversable $ aclValues ) { $ masks = $ data -> getMasks ( ) ; $ acl = $ data -> getAcl ( ) ; $ matrices = $ form -> getData ( ) ; foreach ( $ aclValues as $ aclValue ) { foreach ( $ matrices as $ key => $ matrix ) { if ( $ aclValue instanceof Us...
Builds ACL .
8,250
private function addExtension ( array & $ targets , string $ target , string $ extension , array $ attributes ) : void { if ( ! isset ( $ targets [ $ target ] ) ) { $ targets [ $ target ] = new \ SplPriorityQueue ( ) ; } $ priority = $ attributes [ 'priority' ] ?? 0 ; $ targets [ $ target ] -> insert ( new Reference ( ...
Add extension configuration to the targets array .
8,251
public function addNewInstance ( $ object , FieldDescriptionInterface $ fieldDescription ) { $ instance = $ fieldDescription -> getAssociationAdmin ( ) -> getNewInstance ( ) ; $ mapping = $ fieldDescription -> getAssociationMapping ( ) ; $ method = sprintf ( 'add%s' , Inflector :: classify ( $ mapping [ 'fieldName' ] )...
Add a new instance to the related FieldDescriptionInterface value .
8,252
public function getElementAccessPath ( $ elementId , $ entity ) { $ propertyAccessor = $ this -> pool -> getPropertyAccessor ( ) ; $ idWithoutIdentifier = preg_replace ( '/^[^_]*_/' , '' , $ elementId ) ; $ initialPath = preg_replace ( '#(_(\d+)_)#' , '[$2]_' , $ idWithoutIdentifier ) ; $ parts = explode ( '_' , $ init...
Get access path to element which works with PropertyAccessor .
8,253
protected function getEntityClassName ( AdminInterface $ admin , $ elements ) { $ element = array_shift ( $ elements ) ; $ associationAdmin = $ admin -> getFormFieldDescription ( $ element ) -> getAssociationAdmin ( ) ; if ( 0 === \ count ( $ elements ) ) { return $ associationAdmin -> getClass ( ) ; } return $ this ->...
Recursively find the class name of the admin responsible for the element at the end of an association chain .
8,254
public function getUserPermissions ( ) { $ permissions = $ this -> getPermissions ( ) ; if ( ! $ this -> isOwner ( ) ) { foreach ( self :: $ ownerPermissions as $ permission ) { $ key = array_search ( $ permission , $ permissions , true ) ; if ( false !== $ key ) { unset ( $ permissions [ $ key ] ) ; } } } return $ per...
Get permissions that the current user can set .
8,255
protected function updateMasks ( ) { $ permissions = $ this -> getPermissions ( ) ; $ reflectionClass = new \ ReflectionClass ( new $ this -> maskBuilderClass ( ) ) ; $ this -> masks = [ ] ; foreach ( $ permissions as $ permission ) { $ this -> masks [ $ permission ] = $ reflectionClass -> getConstant ( 'MASK_' . $ per...
Cache masks .
8,256
public function getLinks ( $ nbLinks = null ) { if ( null === $ nbLinks ) { $ nbLinks = $ this -> getMaxPageLinks ( ) ; } $ links = [ ] ; $ tmp = $ this -> page - floor ( $ nbLinks / 2 ) ; $ check = $ this -> lastPage - $ nbLinks + 1 ; $ limit = $ check > 0 ? $ check : 1 ; $ begin = $ tmp > 0 ? ( $ tmp > $ limit ? $ li...
Returns an array of page numbers to use in pagination links .
8,257
public function setCursor ( $ pos ) { if ( $ pos < 1 ) { $ this -> cursor = 1 ; } else { if ( $ pos > $ this -> nbResults ) { $ this -> cursor = $ this -> nbResults ; } else { $ this -> cursor = $ pos ; } } }
Sets the current cursor .
8,258
protected function initializeIterator ( ) { $ this -> results = $ this -> getResults ( ) ; $ this -> resultsCounter = \ count ( $ this -> results ) ; }
Loads data into properties used for iteration .
8,259
protected function retrieveObject ( $ offset ) { $ queryForRetrieve = clone $ this -> getQuery ( ) ; $ queryForRetrieve -> setFirstResult ( $ offset - 1 ) -> setMaxResults ( 1 ) ; $ results = $ queryForRetrieve -> execute ( ) ; return $ results [ 0 ] ; }
Retrieve the object for a certain offset .
8,260
private function generateFallback ( $ name ) : void { if ( empty ( $ name ) ) { return ; } if ( preg_match ( AdminClass :: CLASS_REGEX , $ name , $ matches ) ) { if ( empty ( $ this -> group ) ) { $ this -> group = $ matches [ 3 ] ; } if ( empty ( $ this -> label ) ) { $ this -> label = $ matches [ 5 ] ; } } }
Set group and label from class name it not set .
8,261
public function applyConfigurationFromAttribute ( Definition $ definition , array $ attributes ) { $ keys = [ 'model_manager' , 'form_contractor' , 'show_builder' , 'list_builder' , 'datagrid_builder' , 'translator' , 'configuration_pool' , 'router' , 'validator' , 'security_handler' , 'menu_factory' , 'route_builder' ...
This method read the attribute keys and configure admin class to use the related dependency .
8,262
private function replaceDefaultArguments ( array $ defaultArguments , Definition $ definition , Definition $ parentDefinition = null ) : void { $ arguments = $ definition -> getArguments ( ) ; $ parentArguments = $ parentDefinition ? $ parentDefinition -> getArguments ( ) : [ ] ; foreach ( $ defaultArguments as $ index...
Replace the empty arguments required by the Admin service definition .
8,263
public function configureAcls ( OutputInterface $ output , AdminInterface $ admin , \ Traversable $ oids , UserSecurityIdentity $ securityIdentity = null ) { $ countAdded = 0 ; $ countUpdated = 0 ; $ securityHandler = $ admin -> getSecurityHandler ( ) ; if ( ! $ securityHandler instanceof AclSecurityHandlerInterface ) ...
Configure the object ACL for the passed object identities .
8,264
private function retrieveFilterFieldDescription ( AdminInterface $ admin , string $ field ) : FieldDescriptionInterface { $ admin -> getFilterFieldDescriptions ( ) ; $ fieldDescription = $ admin -> getFilterFieldDescription ( $ field ) ; if ( ! $ fieldDescription ) { throw new \ RuntimeException ( sprintf ( 'The field ...
Retrieve the filter field description given by field name .
8,265
public function getInstance ( $ id ) { if ( ! \ in_array ( $ id , $ this -> adminServiceIds , true ) ) { $ msg = sprintf ( 'Admin service "%s" not found in admin pool.' , $ id ) ; $ shortest = - 1 ; $ closest = null ; $ alternatives = [ ] ; foreach ( $ this -> adminServiceIds as $ adminServiceId ) { $ lev = levenshtein...
Returns a new admin instance depends on the given code .
8,266
public function getAvailableFormats ( AdminInterface $ admin ) : array { $ adminExportFormats = $ admin -> getExportFormats ( ) ; if ( $ adminExportFormats !== [ 'json' , 'xml' , 'csv' , 'xls' ] ) { return $ adminExportFormats ; } return $ this -> exporter -> getAvailableFormats ( ) ; }
Queries an admin for its default export formats and falls back on global settings .
8,267
public function getExportFilename ( AdminInterface $ admin , string $ format ) : string { $ class = $ admin -> getClass ( ) ; return sprintf ( 'export_%s_%s.%s' , strtolower ( substr ( $ class , strripos ( $ class , '\\' ) + 1 ) ) , date ( 'Y_m_d_H_i_s' , strtotime ( 'now' ) ) , $ format ) ; }
Builds an export filename from the class associated with the provided admin the current date and the provided format .
8,268
public function searchAction ( Request $ request ) { $ searchAction = $ this -> container -> get ( SearchAction :: class ) ; return $ searchAction ( $ request ) ; }
The search action first render an empty page if the query is set then the template generates some ajax request to retrieve results for each admin . The Ajax query returns a JSON response .
8,269
private function guess ( \ Closure $ closure ) : Guess { $ guesses = [ ] ; foreach ( $ this -> guessers as $ guesser ) { if ( $ guess = $ closure ( $ guesser ) ) { $ guesses [ ] = $ guess ; } } return Guess :: getBestGuess ( $ guesses ) ; }
Executes a closure for each guesser and returns the best guess from the return values .
8,270
public function initialize ( ) { if ( ! $ this -> classnameLabel ) { $ this -> classnameLabel = substr ( ( string ) $ this -> getClass ( ) , strrpos ( ( string ) $ this -> getClass ( ) , '\\' ) + 1 ) ; } $ this -> baseCodeRoute = $ this -> getCode ( ) ; $ this -> configure ( ) ; }
define custom variable .
8,271
public function getBaseRoutePattern ( ) { if ( null !== $ this -> cachedBaseRoutePattern ) { return $ this -> cachedBaseRoutePattern ; } if ( $ this -> isChild ( ) ) { $ baseRoutePattern = $ this -> baseRoutePattern ; if ( ! $ this -> baseRoutePattern ) { preg_match ( self :: CLASS_REGEX , $ this -> class , $ matches )...
Returns the baseRoutePattern used to generate the routing information .
8,272
public function getBaseRouteName ( ) { if ( null !== $ this -> cachedBaseRouteName ) { return $ this -> cachedBaseRouteName ; } if ( $ this -> isChild ( ) ) { $ baseRouteName = $ this -> baseRouteName ; if ( ! $ this -> baseRouteName ) { preg_match ( self :: CLASS_REGEX , $ this -> class , $ matches ) ; if ( ! $ matche...
Returns the baseRouteName used to generate the routing information .
8,273
public function buildBreadcrumbs ( $ action , MenuItemInterface $ menu = null ) { @ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 3.2 and will be removed in 4.0.' , E_USER_DEPRECATED ) ; if ( isset ( $ this -> breadcrumbs [ $ action ] ) ) { return $ this -> breadcrumbs [ $ action ] ; } retu...
Generates the breadcrumbs array .
8,274
public function hasAccess ( $ action , $ object = null ) { $ access = $ this -> getAccess ( ) ; if ( ! \ array_key_exists ( $ action , $ access ) ) { return false ; } if ( ! \ is_array ( $ access [ $ action ] ) ) { $ access [ $ action ] = [ $ access [ $ action ] ] ; } foreach ( $ access [ $ action ] as $ role ) { if ( ...
Hook to handle access authorization without throw Exception .
8,275
public function getDashboardActions ( ) { $ actions = [ ] ; if ( $ this -> hasRoute ( 'create' ) && $ this -> hasAccess ( 'create' ) ) { $ actions [ 'create' ] = [ 'label' => 'link_add' , 'translation_domain' => 'SonataAdminBundle' , 'template' => $ this -> getTemplate ( 'action_create' ) , 'url' => $ this -> generateU...
Get the list of actions that can be accessed directly from the dashboard .
8,276
final public function isDefaultFilter ( $ name ) { $ filter = $ this -> getFilterParameters ( ) ; $ default = $ this -> getDefaultFilterValues ( ) ; if ( ! \ array_key_exists ( $ name , $ filter ) || ! \ array_key_exists ( $ name , $ default ) ) { return false ; } return $ filter [ $ name ] === $ default [ $ name ] ; }
Checks if a filter type is set to a default value .
8,277
public function canAccessObject ( $ action , $ object ) { return $ object && $ this -> id ( $ object ) && $ this -> hasAccess ( $ action , $ object ) ; }
Check object existence and access without throw Exception .
8,278
final protected function getDefaultFilterValues ( ) { $ defaultFilterValues = [ ] ; $ this -> configureDefaultFilterValues ( $ defaultFilterValues ) ; foreach ( $ this -> getExtensions ( ) as $ extension ) { if ( method_exists ( $ extension , 'configureDefaultFilterValues' ) ) { $ extension -> configureDefaultFilterVal...
Returns a list of default filters .
8,279
protected function configureTabMenu ( MenuItemInterface $ menu , $ action , AdminInterface $ childAdmin = null ) { $ this -> configureSideMenu ( $ menu , $ action , $ childAdmin ) ; }
Configures the tab menu in your admin .
8,280
protected function buildShow ( ) { if ( $ this -> show ) { return ; } $ this -> show = new FieldDescriptionCollection ( ) ; $ mapper = new ShowMapper ( $ this -> showBuilder , $ this -> show , $ this ) ; $ this -> configureShowFields ( $ mapper ) ; foreach ( $ this -> getExtensions ( ) as $ extension ) { $ extension ->...
build the view FieldDescription array .
8,281
protected function buildList ( ) { if ( $ this -> list ) { return ; } $ this -> list = $ this -> getListBuilder ( ) -> getBaseList ( ) ; $ mapper = new ListMapper ( $ this -> getListBuilder ( ) , $ this -> list , $ this ) ; if ( \ count ( $ this -> getBatchActions ( ) ) > 0 && $ this -> hasRequest ( ) && ! $ this -> ge...
build the list FieldDescription array .
8,282
protected function buildForm ( ) { if ( $ this -> form ) { return ; } if ( $ this -> isChild ( ) && $ this -> getParentAssociationMapping ( ) ) { $ parent = $ this -> getParent ( ) -> getObject ( $ this -> request -> get ( $ this -> getParent ( ) -> getIdParameter ( ) ) ) ; $ propertyAccessor = $ this -> getConfigurati...
Build the form FieldDescription collection .
8,283
protected function getSubClass ( $ name ) { if ( $ this -> hasSubClass ( $ name ) ) { return $ this -> subClasses [ $ name ] ; } throw new \ RuntimeException ( sprintf ( 'Unable to find the subclass `%s` for admin `%s`' , $ name , \ get_class ( $ this ) ) ) ; }
Gets the subclass corresponding to the given name .
8,284
protected function attachInlineValidator ( ) { $ admin = $ this ; $ metadata = $ this -> validator -> getMetadataFor ( $ this -> getClass ( ) ) ; $ metadata -> addConstraint ( new InlineConstraint ( [ 'service' => $ this , 'method' => static function ( ErrorElement $ errorElement , $ object ) use ( $ admin ) { if ( $ a...
Attach the inline validator to the model metadata this must be done once per admin .
8,285
protected function predefinePerPageOptions ( ) { array_unshift ( $ this -> perPageOptions , $ this -> maxPerPage ) ; $ this -> perPageOptions = array_unique ( $ this -> perPageOptions ) ; sort ( $ this -> perPageOptions ) ; }
Predefine per page options .
8,286
protected function getAccess ( ) { $ access = array_merge ( [ 'acl' => 'MASTER' , 'export' => 'EXPORT' , 'historyCompareRevisions' => 'EDIT' , 'historyViewRevision' => 'EDIT' , 'history' => 'EDIT' , 'edit' => 'EDIT' , 'show' => 'VIEW' , 'create' => 'CREATE' , 'delete' => 'DELETE' , 'batchDelete' => 'DELETE' , 'list' =>...
Return list routes with permissions name .
8,287
private function buildRoutes ( ) : void { if ( $ this -> loaded [ 'routes' ] ) { return ; } $ this -> loaded [ 'routes' ] = true ; $ this -> routes = new RouteCollection ( $ this -> getBaseCodeRoute ( ) , $ this -> getBaseRouteName ( ) , $ this -> getBaseRoutePattern ( ) , $ this -> getBaseControllerName ( ) ) ; $ this...
Build all the related urls to the current admin .
8,288
public function actionify ( $ action ) { if ( false !== ( $ pos = strrpos ( $ action , '.' ) ) ) { $ action = substr ( $ action , $ pos + 1 ) ; } if ( false === strpos ( $ this -> baseControllerName , ':' ) ) { $ action .= 'Action' ; } return lcfirst ( str_replace ( ' ' , '' , ucwords ( strtr ( $ action , '_-' , ' ' )...
Convert a word in to the format for a symfony action action_name = > actionName .
8,289
public function get ( $ name , array $ options = [ ] ) { $ group = $ options [ 'group' ] ; $ menuItem = $ this -> menuFactory -> createItem ( $ options [ 'name' ] ) ; if ( empty ( $ group [ 'on_top' ] ) || false === $ group [ 'on_top' ] ) { foreach ( $ group [ 'items' ] as $ item ) { if ( $ this -> canGenerateMenuItem ...
Retrieves the menu based on the group options .
8,290
public function renderWithExtraParams ( $ view , array $ parameters = [ ] , Response $ response = null ) { if ( ! $ this -> isXmlHttpRequest ( ) ) { $ parameters [ 'breadcrumbs_builder' ] = $ this -> get ( 'sonata.admin.breadcrumbs_builder' ) ; } $ parameters [ 'admin' ] = $ parameters [ 'admin' ] ?? $ this -> admin ; ...
Renders a view while passing mandatory parameters on to the template .
8,291
public function batchActionDelete ( ProxyQueryInterface $ query ) { $ this -> admin -> checkAccess ( 'batchDelete' ) ; $ modelManager = $ this -> admin -> getModelManager ( ) ; try { $ modelManager -> batchDelete ( $ this -> admin -> getClass ( ) , $ query ) ; $ this -> addFlash ( 'sonata_flash_success' , $ this -> tra...
Execute a batch delete .
8,292
public function showAction ( $ id = null ) { $ request = $ this -> getRequest ( ) ; $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> getObject ( $ id ) ; if ( ! $ object ) { throw $ this -> createNotFoundException ( sprintf ( 'unable to find the object with id: %s' , $ i...
Show action .
8,293
public function historyAction ( $ id = null ) { $ request = $ this -> getRequest ( ) ; $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> getObject ( $ id ) ; if ( ! $ object ) { throw $ this -> createNotFoundException ( sprintf ( 'unable to find the object with id: %s' , ...
Show history revisions for object .
8,294
public function historyViewRevisionAction ( $ id = null , $ revision = null ) { $ request = $ this -> getRequest ( ) ; $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> getObject ( $ id ) ; if ( ! $ object ) { throw $ this -> createNotFoundException ( sprintf ( 'unable to...
View history revision of object .
8,295
public function historyCompareRevisionsAction ( $ id = null , $ base_revision = null , $ compare_revision = null ) { $ request = $ this -> getRequest ( ) ; $ this -> admin -> checkAccess ( 'historyCompareRevisions' ) ; $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> get...
Compare history revisions of object .
8,296
public function exportAction ( Request $ request ) { $ this -> admin -> checkAccess ( 'export' ) ; $ format = $ request -> get ( 'format' ) ; if ( ! $ this -> has ( 'sonata.admin.admin_exporter' ) ) { @ trigger_error ( 'Not registering the exporter bundle is deprecated since version 3.14.' . ' You must register it to b...
Export data to specified format .
8,297
public function aclAction ( $ id = null ) { $ request = $ this -> getRequest ( ) ; if ( ! $ this -> admin -> isAclEnabled ( ) ) { throw $ this -> createNotFoundException ( 'ACL are not enabled for this admin' ) ; } $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> getObje...
Returns the Response object associated to the acl action .
8,298
protected function getRestMethod ( ) { $ request = $ this -> getRequest ( ) ; if ( Request :: getHttpMethodParameterOverride ( ) || ! $ request -> request -> has ( '_method' ) ) { return $ request -> getMethod ( ) ; } return $ request -> request -> get ( '_method' ) ; }
Returns the correct RESTful verb given either by the request itself or via the _method parameter .
8,299
protected function configure ( ) { $ request = $ this -> getRequest ( ) ; $ adminCode = $ request -> get ( '_sonata_admin' ) ; if ( ! $ adminCode ) { throw new \ RuntimeException ( sprintf ( 'There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`' , \ get_class ( $ this ) , $ request -> ...
Contextualize the admin class depends on the current request .