Zend Framework 2 : Disable some toolbar entries from ZendDeveloperTools
Sometime, when we are working with modules that provide a new toolbar entries, then we no need to keep the default ZendDeveloperTools toolbar entries because it replaced by new toolbar entries. For example, we are working with Doctrine and we use DoctrineORMModule, we automatically get the toolbar like this :
![]()
What if we need to eliminate the Zend\Db toolbar entry from the toolbar ? Let’s take a look at ZendDeveloperTools Options for it one by one method to know what’s going on :
1. Take a look at ZendDeveloperTools\Options $toolbar property :
namespace ZendDeveloperTools;
use Zend\Stdlib\AbstractOptions;
class Options extends AbstractOptions
{
/*** Other properties here ***/
/**
* @var array
*/
protected $toolbar = array(
'enabled' => false,
'auto_hide' => false,
'position' => 'bottom',
'version_check' => false,
'entries' => array(
'request' => 'zend-developer-tools/toolbar/request',
'time' => 'zend-developer-tools/toolbar/time',
'memory' => 'zend-developer-tools/toolbar/memory',
'config' => 'zend-developer-tools/toolbar/config',
'db' => 'zend-developer-tools/toolbar/db',
),
);
/*** Options methods here ***/
}
Now, we know that the toolbar entry for Zend\Db is the entries with key ‘db’.
2. There is a method to setToolbar with its logic
namespace ZendDeveloperTools;
use Zend\Stdlib\AbstractOptions;
class Options extends AbstractOptions
{
/*** Options properties here ***/
/**
* Sets Toolbar options.
*
* @param array $options
*/
public function setToolbar(array $options)
{
/*** other logic here ***/
if (isset($options['entries'])) {
if (is_array($options['entries'])) {
foreach ($options['entries'] as $collector => $template) {
if ($template === false || $template === null) {
unset($this->toolbar['entries'][$collector]);
} else {
$this->toolbar['entries'][$collector] = $template;
}
}
}
/*** other logic here ***/
}
}
/*** other Options methods here ***/
}
Now, we know, to unset the entries, we need to make the ‘value’ of its key false or null.
3. Last step, setting up the config/autoload/zenddevelopertools.local.php :
return array(
'zenddevelopertools' => array(
'profiler' => array( /** other config here **/ ),
'events' => array( /** other config here **/ ),
'toolbar' => array(
/** other config here **/
'entries' => array(
'db' => false,
)
),
),
);
Done, now, our ZendDeveloperTools toolbar will look like this :
![]()
8 comments