public function injectOperationButton($screen)
{
$parentTable = $screen->getParentTable();
$parentDCA =& $GLOBALS['TL_DCA'][$parentTable];
$dispatcher = $this->getDispatcher();
$metaModel = $screen->getMetaModel();
$event = new LoadLanguageFileEvent('default');
$dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
$arrCaption = array(sprintf($GLOBALS['TL_LANG']['MSC']['metamodel_edit_as_child']['label'], $metaModel->getName()), '');
foreach ($screen->getBackendCaption() as $arrLangEntry) {
if ($arrLangEntry['label'] != '' && $arrLangEntry['langcode'] == $GLOBALS['TL_LANGUAGE']) {
$arrCaption = array($arrLangEntry['label'], $arrLangEntry['description']);
}
}
$parentDCA['list']['operations']['edit_' . $metaModel->getTableName()] = array('label' => &$arrCaption, 'href' => 'table=' . $metaModel->getTableName(), 'icon' => $this->getBackendIcon($screen->getIcon()), 'attributes' => 'onclick="Backend.getScrollOffset()"');
$operationName = 'edit_' . $metaModel->getTableName();
// Is the destination table a metamodel with variants?
if ($metaModel->hasVariants()) {
$parentDCA['list']['operations'][$operationName]['idparam'] = 'id_' . $parentTable;
} else {
$parentDCA['list']['operations'][$operationName]['idparam'] = 'pid';
}
// Compatibility with DC_Table.
if ($parentDCA['config']['dataContainer'] !== 'General') {
$handler = $this;
$idParameter = $parentDCA['list']['operations'][$operationName]['idparam'];
$parentDCA['list']['operations'][$operationName]['button_callback'] = OperationButtonCallbackListener::generateFor($parentTable, $operationName, function ($row, $href, $label, $name, $icon, $attributes, $table) use($handler, $idParameter) {
return $handler->buildChildOperationButton($idParameter, $row, $href, $label, $name, $icon, $attributes, $table);
});
}
}