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:
Complex classes like GridField often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GridField, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class GridField extends FormField { |
||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | private static $allowed_actions = array( |
||
|
|
|||
| 27 | 'index', |
||
| 28 | 'gridFieldAlterAction', |
||
| 29 | ); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Data source. |
||
| 33 | * |
||
| 34 | * @var SS_List |
||
| 35 | */ |
||
| 36 | protected $list = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Class name of the DataObject that the GridField will display. |
||
| 40 | * |
||
| 41 | * Defaults to the value of $this->list->dataClass. |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | protected $modelClassName = ''; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Current state of the GridField. |
||
| 49 | * |
||
| 50 | * @var GridState |
||
| 51 | */ |
||
| 52 | protected $state = null; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var GridFieldConfig |
||
| 56 | */ |
||
| 57 | protected $config = null; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Components list. |
||
| 61 | * |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | protected $components = array(); |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Internal dispatcher for column handlers. |
||
| 68 | * |
||
| 69 | * Keys are column names and values are GridField_ColumnProvider objects. |
||
| 70 | * |
||
| 71 | * @var array |
||
| 72 | */ |
||
| 73 | protected $columnDispatch = null; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Map of callbacks for custom data fields. |
||
| 77 | * |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | protected $customDataFields = array(); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var string |
||
| 84 | */ |
||
| 85 | protected $name = ''; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $name |
||
| 89 | * @param string $title |
||
| 90 | * @param SS_List $dataList |
||
| 91 | * @param GridFieldConfig $config |
||
| 92 | */ |
||
| 93 | public function __construct($name, $title = null, SS_List $dataList = null, GridFieldConfig $config = null) { |
||
| 94 | parent::__construct($name, $title, null); |
||
| 95 | |||
| 96 | $this->name = $name; |
||
| 97 | |||
| 98 | if($dataList) { |
||
| 99 | $this->setList($dataList); |
||
| 100 | } |
||
| 101 | |||
| 102 | if(!$config) { |
||
| 103 | $config = GridFieldConfig_Base::create(); |
||
| 104 | } |
||
| 105 | |||
| 106 | $this->setConfig($config); |
||
| 107 | |||
| 108 | $this->config->addComponent(new GridState_Component()); |
||
| 109 | $this->state = new GridState($this); |
||
| 110 | |||
| 111 | $this->addExtraClass('ss-gridfield'); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param SS_HTTPRequest $request |
||
| 116 | * |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | public function index($request) { |
||
| 120 | return $this->gridFieldAlterAction(array(), $this->getForm(), $request); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Set the modelClass (data object) that this field will get it column headers from. |
||
| 125 | * |
||
| 126 | * If no $displayFields has been set, the display fields will be $summary_fields. |
||
| 127 | * |
||
| 128 | * @see GridFieldDataColumns::getDisplayFields() |
||
| 129 | * |
||
| 130 | * @param string $modelClassName |
||
| 131 | * |
||
| 132 | * @return $this |
||
| 133 | */ |
||
| 134 | public function setModelClass($modelClassName) { |
||
| 135 | $this->modelClassName = $modelClassName; |
||
| 136 | |||
| 137 | return $this; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Returns a data class that is a DataObject type that this GridField should look like. |
||
| 142 | * |
||
| 143 | * @return string |
||
| 144 | * |
||
| 145 | * @throws LogicException |
||
| 146 | */ |
||
| 147 | public function getModelClass() { |
||
| 148 | if($this->modelClassName) { |
||
| 149 | return $this->modelClassName; |
||
| 150 | } |
||
| 151 | |||
| 152 | if($this->list && $this->list->hasMethod('dataClass')) { |
||
| 153 | $class = $this->list->dataClass(); |
||
| 154 | |||
| 155 | if($class) { |
||
| 156 | return $class; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | throw new LogicException( |
||
| 161 | 'GridField doesn\'t have a modelClassName, so it doesn\'t know the columns of this grid.' |
||
| 162 | ); |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return GridFieldConfig |
||
| 167 | */ |
||
| 168 | public function getConfig() { |
||
| 169 | return $this->config; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param GridFieldConfig $config |
||
| 174 | * |
||
| 175 | * @return $this |
||
| 176 | */ |
||
| 177 | public function setConfig(GridFieldConfig $config) { |
||
| 178 | $this->config = $config; |
||
| 179 | |||
| 180 | return $this; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return ArrayList |
||
| 185 | */ |
||
| 186 | public function getComponents() { |
||
| 187 | return $this->config->getComponents(); |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Cast an arbitrary value with the help of a $castingDefinition. |
||
| 192 | * |
||
| 193 | * @todo refactor this into GridFieldComponent |
||
| 194 | * |
||
| 195 | * @param mixed $value |
||
| 196 | * @param string|array $castingDefinition |
||
| 197 | * |
||
| 198 | * @return mixed |
||
| 199 | */ |
||
| 200 | public function getCastedValue($value, $castingDefinition) { |
||
| 201 | $castingParams = array(); |
||
| 202 | |||
| 203 | if(is_array($castingDefinition)) { |
||
| 204 | $castingParams = $castingDefinition; |
||
| 205 | array_shift($castingParams); |
||
| 206 | $castingDefinition = array_shift($castingDefinition); |
||
| 207 | } |
||
| 208 | |||
| 209 | if(strpos($castingDefinition, '->') === false) { |
||
| 210 | $castingFieldType = $castingDefinition; |
||
| 211 | $castingField = DBField::create_field($castingFieldType, $value); |
||
| 212 | |||
| 213 | return call_user_func_array(array($castingField, 'XML'), $castingParams); |
||
| 214 | } |
||
| 215 | |||
| 216 | list($castingFieldType, $castingMethod) = explode('->', $castingDefinition); |
||
| 217 | |||
| 218 | $castingField = DBField::create_field($castingFieldType, $value); |
||
| 219 | |||
| 220 | return call_user_func_array(array($castingField, $castingMethod), $castingParams); |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set the data source. |
||
| 225 | * |
||
| 226 | * @param SS_List $list |
||
| 227 | * |
||
| 228 | * @return $this |
||
| 229 | */ |
||
| 230 | public function setList(SS_List $list) { |
||
| 231 | $this->list = $list; |
||
| 232 | |||
| 233 | return $this; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get the data source. |
||
| 238 | * |
||
| 239 | * @return SS_List |
||
| 240 | */ |
||
| 241 | public function getList() { |
||
| 242 | return $this->list; |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Get the data source after applying every {@link GridField_DataManipulator} to it. |
||
| 247 | * |
||
| 248 | * @return SS_List |
||
| 249 | */ |
||
| 250 | public function getManipulatedList() { |
||
| 251 | $list = $this->getList(); |
||
| 252 | |||
| 253 | foreach($this->getComponents() as $item) { |
||
| 254 | if($item instanceof GridField_DataManipulator) { |
||
| 255 | $list = $item->getManipulatedData($this, $list); |
||
| 256 | } |
||
| 257 | } |
||
| 258 | |||
| 259 | return $list; |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Get the current GridState_Data or the GridState. |
||
| 264 | * |
||
| 265 | * @param bool $getData |
||
| 266 | * |
||
| 267 | * @return GridState_Data|GridState |
||
| 268 | */ |
||
| 269 | public function getState($getData = true) { |
||
| 270 | if($getData) { |
||
| 271 | return $this->state->getData(); |
||
| 272 | } |
||
| 273 | |||
| 274 | return $this->state; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Returns the whole gridfield rendered with all the attached components. |
||
| 279 | * |
||
| 280 | * @param array $properties |
||
| 281 | * |
||
| 282 | * @return HTMLText |
||
| 283 | */ |
||
| 284 | public function FieldHolder($properties = array()) { |
||
| 285 | Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); |
||
| 286 | Requirements::css(FRAMEWORK_DIR . '/css/GridField.css'); |
||
| 287 | |||
| 288 | Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); |
||
| 289 | Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); |
||
| 290 | Requirements::javascript(THIRDPARTY_DIR . '/json-js/json2.js'); |
||
| 291 | Requirements::javascript(FRAMEWORK_DIR . '/javascript/i18n.js'); |
||
| 292 | Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang'); |
||
| 293 | Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); |
||
| 294 | Requirements::javascript(FRAMEWORK_DIR . '/javascript/GridField.js'); |
||
| 295 | |||
| 296 | $columns = $this->getColumns(); |
||
| 297 | |||
| 298 | $list = $this->getManipulatedList(); |
||
| 299 | |||
| 300 | $content = array( |
||
| 301 | 'before' => '', |
||
| 302 | 'after' => '', |
||
| 303 | 'header' => '', |
||
| 304 | 'footer' => '', |
||
| 305 | ); |
||
| 306 | |||
| 307 | foreach($this->getComponents() as $item) { |
||
| 308 | if($item instanceof GridField_HTMLProvider) { |
||
| 309 | $fragments = $item->getHTMLFragments($this); |
||
| 310 | |||
| 311 | if($fragments) { |
||
| 312 | foreach($fragments as $fragmentKey => $fragmentValue) { |
||
| 313 | $fragmentKey = strtolower($fragmentKey); |
||
| 314 | |||
| 315 | if(!isset($content[$fragmentKey])) { |
||
| 316 | $content[$fragmentKey] = ''; |
||
| 317 | } |
||
| 318 | |||
| 319 | $content[$fragmentKey] .= $fragmentValue . "\n"; |
||
| 320 | } |
||
| 321 | } |
||
| 322 | } |
||
| 323 | } |
||
| 324 | |||
| 325 | foreach($content as $contentKey => $contentValue) { |
||
| 326 | $content[$contentKey] = trim($contentValue); |
||
| 327 | } |
||
| 328 | |||
| 329 | // Replace custom fragments and check which fragments are defined. Circular dependencies |
||
| 330 | // are detected by disallowing any item to be deferred more than 5 times. |
||
| 331 | |||
| 332 | $fragmentDefined = array( |
||
| 333 | 'header' => true, |
||
| 334 | 'footer' => true, |
||
| 335 | 'before' => true, |
||
| 336 | 'after' => true, |
||
| 337 | ); |
||
| 338 | |||
| 339 | reset($content); |
||
| 340 | |||
| 341 | while(list($contentKey, $contentValue) = each($content)) { |
||
| 342 | if(preg_match_all('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $contentValue, $matches)) { |
||
| 343 | foreach($matches[1] as $match) { |
||
| 344 | $fragmentName = strtolower($match); |
||
| 345 | $fragmentDefined[$fragmentName] = true; |
||
| 346 | |||
| 347 | $fragment = ''; |
||
| 348 | |||
| 349 | if(isset($content[$fragmentName])) { |
||
| 350 | $fragment = $content[$fragmentName]; |
||
| 351 | } |
||
| 352 | |||
| 353 | // If the fragment still has a fragment definition in it, when we should defer |
||
| 354 | // this item until later. |
||
| 355 | |||
| 356 | if(preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $fragment, $matches)) { |
||
| 357 | if(isset($fragmentDeferred[$contentKey]) && $fragmentDeferred[$contentKey] > 5) { |
||
| 358 | throw new LogicException(sprintf( |
||
| 359 | 'GridField HTML fragment "%s" and "%s" appear to have a circular dependency.', |
||
| 360 | $fragmentName, |
||
| 361 | $matches[1] |
||
| 362 | )); |
||
| 363 | } |
||
| 364 | |||
| 365 | unset($content[$contentKey]); |
||
| 366 | |||
| 367 | $content[$contentKey] = $contentValue; |
||
| 368 | |||
| 369 | if(!isset($fragmentDeferred[$contentKey])) { |
||
| 370 | $fragmentDeferred[$contentKey] = 0; |
||
| 371 | } |
||
| 372 | |||
| 373 | $fragmentDeferred[$contentKey]++; |
||
| 374 | |||
| 375 | break; |
||
| 376 | } else { |
||
| 377 | $content[$contentKey] = preg_replace( |
||
| 378 | sprintf('/\$DefineFragment\(%s\)/i', $fragmentName), |
||
| 379 | $fragment, |
||
| 380 | $content[$contentKey] |
||
| 381 | ); |
||
| 382 | } |
||
| 383 | } |
||
| 384 | } |
||
| 385 | } |
||
| 386 | |||
| 387 | // Check for any undefined fragments, and if so throw an exception. |
||
| 388 | // While we're at it, trim whitespace off the elements. |
||
| 389 | |||
| 390 | foreach($content as $contentKey => $contentValue) { |
||
| 391 | if(empty($fragmentDefined[$contentKey])) { |
||
| 392 | throw new LogicException(sprintf( |
||
| 393 | 'GridField HTML fragment "%s" was given content, but not defined. Perhaps there is a supporting GridField component you need to add?', |
||
| 394 | $contentKey |
||
| 395 | )); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | $total = count($list); |
||
| 400 | |||
| 401 | if($total > 0) { |
||
| 402 | $rows = array(); |
||
| 403 | |||
| 404 | foreach($list as $index => $record) { |
||
| 405 | if($record->hasMethod('canView') && !$record->canView()) { |
||
| 406 | continue; |
||
| 407 | } |
||
| 408 | |||
| 409 | $rowContent = ''; |
||
| 410 | |||
| 411 | foreach($this->getColumns() as $column) { |
||
| 412 | $colContent = $this->getColumnContent($record, $column); |
||
| 413 | |||
| 414 | // Null means this columns should be skipped altogether. |
||
| 415 | |||
| 416 | if($colContent === null) { |
||
| 417 | continue; |
||
| 418 | } |
||
| 419 | |||
| 420 | $colAttributes = $this->getColumnAttributes($record, $column); |
||
| 421 | |||
| 422 | $rowContent .= $this->newCell( |
||
| 423 | $total, |
||
| 424 | $index, |
||
| 425 | $record, |
||
| 426 | $colAttributes, |
||
| 427 | $colContent |
||
| 428 | ); |
||
| 429 | } |
||
| 430 | |||
| 431 | $rowAttributes = $this->getRowAttributes($total, $index, $record); |
||
| 432 | |||
| 433 | $rows[] = $this->newRow($total, $index, $record, $rowAttributes, $rowContent); |
||
| 434 | } |
||
| 435 | $content['body'] = implode("\n", $rows); |
||
| 436 | } |
||
| 437 | |||
| 438 | // Display a message when the grid field is empty. |
||
| 439 | |||
| 440 | if(empty($content['body'])) { |
||
| 441 | $cell = FormField::create_tag( |
||
| 442 | 'td', |
||
| 443 | array( |
||
| 444 | 'colspan' => count($columns), |
||
| 445 | ), |
||
| 446 | _t('GridField.NoItemsFound', 'No items found') |
||
| 447 | ); |
||
| 448 | |||
| 449 | $row = FormField::create_tag( |
||
| 450 | 'tr', |
||
| 451 | array( |
||
| 452 | 'class' => 'ss-gridfield-item ss-gridfield-no-items', |
||
| 453 | ), |
||
| 454 | $cell |
||
| 455 | ); |
||
| 456 | |||
| 457 | $content['body'] = $row; |
||
| 458 | } |
||
| 459 | |||
| 460 | $header = $this->getOptionalTableHeader($content); |
||
| 461 | $body = $this->getOptionalTableBody($content); |
||
| 462 | $footer = $this->getOptionalTableFooter($content); |
||
| 463 | |||
| 464 | $this->addExtraClass('ss-gridfield field'); |
||
| 465 | |||
| 466 | $fieldsetAttributes = array_diff_key( |
||
| 467 | $this->getAttributes(), |
||
| 468 | array( |
||
| 469 | 'value' => false, |
||
| 470 | 'type' => false, |
||
| 471 | 'name' => false, |
||
| 472 | ) |
||
| 473 | ); |
||
| 474 | |||
| 475 | $fieldsetAttributes['data-name'] = $this->getName(); |
||
| 476 | |||
| 477 | $tableId = null; |
||
| 478 | |||
| 479 | if($this->id) { |
||
| 480 | $tableId = $this->id; |
||
| 481 | } |
||
| 482 | |||
| 483 | $tableAttributes = array( |
||
| 484 | 'id' => $tableId, |
||
| 485 | 'class' => 'ss-gridfield-table', |
||
| 486 | 'cellpadding' => '0', |
||
| 487 | 'cellspacing' => '0', |
||
| 488 | ); |
||
| 489 | |||
| 490 | if($this->getDescription()) { |
||
| 491 | $content['after'] .= FormField::create_tag( |
||
| 492 | 'span', |
||
| 493 | array('class' => 'description'), |
||
| 494 | $this->getDescription() |
||
| 495 | ); |
||
| 496 | } |
||
| 497 | |||
| 498 | $table = FormField::create_tag( |
||
| 499 | 'table', |
||
| 500 | $tableAttributes, |
||
| 501 | $header . "\n" . $footer . "\n" . $body |
||
| 502 | ); |
||
| 503 | |||
| 504 | $field = DBField::create_field('HTMLText', FormField::create_tag( |
||
| 505 | 'fieldset', |
||
| 506 | $fieldsetAttributes, |
||
| 507 | $content['before'] . $table . $content['after'] |
||
| 508 | )); |
||
| 509 | $field->setOptions(array('shortcodes' => false)); |
||
| 510 | |||
| 511 | return $field; |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @param int $total |
||
| 516 | * @param int $index |
||
| 517 | * @param DataObject $record |
||
| 518 | * @param array $attributes |
||
| 519 | * @param string $content |
||
| 520 | * |
||
| 521 | * @return string |
||
| 522 | */ |
||
| 523 | protected function newCell($total, $index, $record, $attributes, $content) { |
||
| 524 | return FormField::create_tag( |
||
| 525 | 'td', |
||
| 526 | $attributes, |
||
| 527 | $content |
||
| 528 | ); |
||
| 529 | } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * @param int $total |
||
| 533 | * @param int $index |
||
| 534 | * @param DataObject $record |
||
| 535 | * @param array $attributes |
||
| 536 | * @param string $content |
||
| 537 | * |
||
| 538 | * @return string |
||
| 539 | */ |
||
| 540 | protected function newRow($total, $index, $record, $attributes, $content) { |
||
| 541 | return FormField::create_tag( |
||
| 542 | 'tr', |
||
| 543 | $attributes, |
||
| 544 | $content |
||
| 545 | ); |
||
| 546 | } |
||
| 547 | |||
| 548 | /** |
||
| 549 | * @param int $total |
||
| 550 | * @param int $index |
||
| 551 | * @param DataObject $record |
||
| 552 | * |
||
| 553 | * @return array |
||
| 554 | */ |
||
| 555 | protected function getRowAttributes($total, $index, $record) { |
||
| 556 | $rowClasses = $this->newRowClasses($total, $index, $record); |
||
| 557 | |||
| 558 | return array( |
||
| 559 | 'class' => implode(' ', $rowClasses), |
||
| 560 | 'data-id' => $record->ID, |
||
| 561 | 'data-class' => $record->ClassName, |
||
| 562 | ); |
||
| 563 | } |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param int $total |
||
| 567 | * @param int $index |
||
| 568 | * @param DataObject $record |
||
| 569 | * |
||
| 570 | * @return array |
||
| 571 | */ |
||
| 572 | protected function newRowClasses($total, $index, $record) { |
||
| 593 | |||
| 594 | /** |
||
| 595 | * @param array $properties |
||
| 596 | * |
||
| 597 | * @return HTMLText |
||
| 598 | */ |
||
| 599 | public function Field($properties = array()) { |
||
| 600 | $this->extend('onBeforeRender', $this); |
||
| 601 | return $this->FieldHolder($properties); |
||
| 602 | } |
||
| 603 | |||
| 604 | /** |
||
| 605 | * {@inheritdoc} |
||
| 606 | */ |
||
| 607 | public function getAttributes() { |
||
| 608 | return array_merge( |
||
| 615 | |||
| 616 | /** |
||
| 617 | * Get the columns of this GridField, they are provided by attached GridField_ColumnProvider. |
||
| 618 | * |
||
| 619 | * @return array |
||
| 620 | */ |
||
| 621 | public function getColumns() { |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Get the value from a column. |
||
| 635 | * |
||
| 636 | * @param DataObject $record |
||
| 637 | * @param string $column |
||
| 638 | * |
||
| 639 | * @return string |
||
| 640 | * |
||
| 641 | * @throws InvalidArgumentException |
||
| 642 | */ |
||
| 643 | public function getColumnContent($record, $column) { |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Add additional calculated data fields to be used on this GridField |
||
| 669 | * |
||
| 670 | * @param array $fields a map of fieldname to callback. The callback will |
||
| 671 | * be passed the record as an argument. |
||
| 672 | */ |
||
| 673 | public function addDataFields($fields) { |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Get the value of a named field on the given record. |
||
| 683 | * |
||
| 684 | * Use of this method ensures that any special rules around the data for this gridfield are |
||
| 685 | * followed. |
||
| 686 | * |
||
| 687 | * @param DataObject $record |
||
| 688 | * @param string $fieldName |
||
| 689 | * |
||
| 690 | * @return mixed |
||
| 691 | */ |
||
| 692 | public function getDataFieldValue($record, $fieldName) { |
||
| 709 | |||
| 710 | /** |
||
| 711 | * Get extra columns attributes used as HTML attributes. |
||
| 712 | * |
||
| 713 | * @param DataObject $record |
||
| 714 | * @param string $column |
||
| 715 | * |
||
| 716 | * @return array |
||
| 717 | * |
||
| 718 | * @throws LogicException |
||
| 719 | * @throws InvalidArgumentException |
||
| 720 | */ |
||
| 721 | View Code Duplication | public function getColumnAttributes($record, $column) { |
|
| 754 | |||
| 755 | /** |
||
| 756 | * Get metadata for a column. |
||
| 757 | * |
||
| 758 | * @example "array('Title'=>'Email address')" |
||
| 759 | * |
||
| 760 | * @param string $column |
||
| 761 | * |
||
| 762 | * @return array |
||
| 763 | * |
||
| 764 | * @throws LogicException |
||
| 765 | * @throws InvalidArgumentException |
||
| 766 | */ |
||
| 767 | View Code Duplication | public function getColumnMetadata($column) { |
|
| 800 | |||
| 801 | /** |
||
| 802 | * Return how many columns the grid will have. |
||
| 803 | * |
||
| 804 | * @return int |
||
| 805 | */ |
||
| 806 | public function getColumnCount() { |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Build an columnDispatch that maps a GridField_ColumnProvider to a column for reference later. |
||
| 816 | */ |
||
| 817 | protected function buildColumnDispatch() { |
||
| 830 | |||
| 831 | /** |
||
| 832 | * This is the action that gets executed when a GridField_AlterAction gets clicked. |
||
| 833 | * |
||
| 834 | * @param array $data |
||
| 835 | * @param Form $form |
||
| 836 | * @param SS_HTTPRequest $request |
||
| 837 | * |
||
| 838 | * @return string |
||
| 839 | */ |
||
| 840 | public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request) { |
||
| 893 | |||
| 894 | /** |
||
| 895 | * Pass an action on the first GridField_ActionProvider that matches the $actionName. |
||
| 896 | * |
||
| 897 | * @param string $actionName |
||
| 898 | * @param mixed $arguments |
||
| 899 | * @param array $data |
||
| 900 | * |
||
| 901 | * @return mixed |
||
| 902 | * |
||
| 903 | * @throws InvalidArgumentException |
||
| 904 | */ |
||
| 905 | public function handleAlterAction($actionName, $arguments, $data) { |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Custom request handler that will check component handlers before proceeding to the default |
||
| 926 | * implementation. |
||
| 927 | * |
||
| 928 | * @todo copy less code from RequestHandler. |
||
| 929 | * |
||
| 930 | * @param SS_HTTPRequest $request |
||
| 931 | * @param DataModel $model |
||
| 932 | * |
||
| 933 | * @return array|RequestHandler|SS_HTTPResponse|string|void |
||
| 934 | * |
||
| 935 | * @throws SS_HTTPResponse_Exception |
||
| 936 | */ |
||
| 937 | public function handleRequest(SS_HTTPRequest $request, DataModel $model) { |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * {@inheritdoc} |
||
| 1024 | */ |
||
| 1025 | public function saveInto(DataObjectInterface $record) { |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * @param array $content |
||
| 1035 | * |
||
| 1036 | * @return string |
||
| 1037 | */ |
||
| 1038 | protected function getOptionalTableHeader(array $content) { |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * @param array $content |
||
| 1050 | * |
||
| 1051 | * @return string |
||
| 1052 | */ |
||
| 1053 | protected function getOptionalTableBody(array $content) { |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * @param $content |
||
| 1065 | * |
||
| 1066 | * @return string |
||
| 1067 | */ |
||
| 1068 | protected function getOptionalTableFooter($content) { |
||
| 1077 | |||
| 1078 | } |
||
| 1079 | |||
| 1192 |