Skip to content

Instantly share code, notes, and snippets.

@mneuhaus
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mneuhaus/e82e56966f3e333120b2 to your computer and use it in GitHub Desktop.
Save mneuhaus/e82e56966f3e333120b2 to your computer and use it in GitHub Desktop.
Expose Usecases

Object Lifecycle

Initialize Object

As a developer i might need to initialize a object before it is used to render a form.

This would be possible to do by overriding the default 'newAction' like this:

MyController.php

/**
 * @return void
 */
public function newAction() {
	$entity = new SomeEnity();
	... initialize entity ...
	$this->view->assign('entity', $entity);
}

Preprocess Object before saving

As a developer i need a way to do some stuff before saving the entity.

This would be possible by overriding the createAction like this:

MyController.php

/**
 * @param object $entity
 * @return void
 */
public function createAction($entity) {
	... do some stuff with the entity ...
	parent::createAction($entity);
}

Forms

change Field Label

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
      label: 'Some cool Field'

change Field Type

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
      type: Textarea
  • change Field Description

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
      description: 'Lorem ipsum dolor sit amet...'

ignore Field

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
      ignore: true

add validation to field

Entity.php

	/**
	 * @var string
	 * @Flow\Validate(type="NotEmpty")
	 * @Flow\Validate(type="StringLength", options={ "minimum"=5, "maximum"=100 })
	 */
	protected someField;

or

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
      validation: 
        NotEmpty: []
        StringLength: 
          minimum: 5
          maximum: 100

add options to field

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
      optionsProvider: \My\Package\OptionsProvider\SomeOptionsProvider

change order of fields

Expose.yaml

'My\Package\Domain\Entity': 
  fields:
    someField:
    	position: 'start'

Fieldsets

Expose.yaml

'My\Package\Domain\Entity': 
  fieldsets:
    'Some Fieldset': [someField, someOtherField]

Lists

custom query

Expose.yaml

'My\Package\Domain\Entity': 
  queryMethod: findMyEntities

custom global/local/batch actions

Global actions are actions that don't need a concrete object to act upon, main crud action is of course the "new" action

Local actions are actions that need a single object to act upon like 'edit', 'show' or 'delete'

Batch actions are actions that can act upon multiple entites at the same time like for example 'batchDelete'

MyController.php

<?php
class MyController extends CrudController {
	/**
	 * @Expose\Action(type='local')
	 * @param object $entity
	 * @return void
	 */
	public function showAction($entity) {...}

	/**
	 * @Expose\Action(type='global')
	 * @return void
	 */
	public function newAction() {...}
	
	/**
	 * @Expose\Action(type='batch')
	 * @param arra $entities
	 * @return void
	 */
	public function batchDeleteAction($entities) {...}

Search

Expose.yaml

'My\Package\Domain\Entity': 
  searchFields:
    - someField
    - someOtherField

Filters

Expose.yaml

'My\Package\Domain\Entity': 
  filterFields:
    - someField
    - someOtherField

displayed fields

Expose.yaml

'My\Package\Domain\Entity': 
  listColumns:
    - someField
    - someOtherField

Customizing the HTML Markup

override Field template

override Form Layout

override List template

Extending

custom controller with additional actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment