Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 22 | class ButtonGroupRenderer extends ColumnRendererAbstract |
||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Configure the "Button Group" Grid Renderer. |
||
| 27 | */ |
||
| 28 | public function __construct() |
||
| 29 | { |
||
| 30 | $configuration = array( |
||
| 31 | 'sortable' => FALSE, |
||
| 32 | 'canBeHidden' => FALSE, |
||
| 33 | 'width' => '100px', |
||
| 34 | ); |
||
| 35 | parent::__construct($configuration); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Render the "Button Group" in the Grid, e.g. edit, delete, etc.. |
||
| 40 | * |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | public function render() |
||
| 44 | { |
||
| 45 | $components = $this->getModuleLoader()->getGridButtonsComponents(); |
||
| 46 | |||
| 47 | $buttons = [] |
||
| 48 | foreach ($components as $component) { |
||
|
|
|||
| 49 | |||
| 50 | /** @var $view */ |
||
| 51 | $view = GeneralUtility::makeInstance($component); |
||
| 52 | $buttons[] = $view->render($this->getObject()); |
||
| 53 | } |
||
| 54 | |||
| 55 | $output = sprintf( |
||
| 56 | '<div class="btn-toolbar pull-right" role="toolbar" aria-label=""><div class="btn-group" role="group" aria-label="">%s</div></div>', |
||
| 57 | implode("\n", $buttons) |
||
| 58 | ); |
||
| 59 | |||
| 60 | return $output; |
||
| 61 | } |
||
| 62 | |||
| 63 | } |
||
| 64 |