Skip to content

Instantly share code, notes, and snippets.

@manuakasam
Forked from bakura10/gist:4355470
Created December 21, 2012 20:52
Show Gist options
  • Save manuakasam/4355732 to your computer and use it in GitHub Desktop.
Save manuakasam/4355732 to your computer and use it in GitHub Desktop.
<?php
class Foo
{
protected $labelCallable;
public function setLabelCallable($labelCallable)
{
$this->labelCallable = $labelCallable;
}
...
public function doSomething()
{
// find your object...
$object = ...;
if (is_callable($this->labelCallable)) {
$label = $this->labelCallable($object);
}
}
}
// So in your form you can do something like this :
$this->add(array(
'name' => 'someName',
'type' => 'MyNamespace\Form\Element\EntitySelect',
'attributes' => array(
'required' => true
),
'options' => array(
'label' => 'Select element Label',
'empty_option' => '--- Choose Entity ---',
'object_manager' => $this->getEntityManager(),
'target_class' => 'MyNamespace\Entity\TargetEntity',
'label_callable' => function($object) {
return $object->propertyOne + ' - ' + $objectPropertyTwo;
}
)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment