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 contentBlueprintsPages 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 contentBlueprintsPages, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class contentBlueprintsPages extends AdministrationPage |
||
| 14 | { |
||
| 15 | public $_errors = array(); |
||
| 16 | protected $_hilights = array(); |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The Pages page has /action/id/flag/ context. |
||
| 20 | * eg. /edit/1/saved/ |
||
| 21 | * |
||
| 22 | * @param array $context |
||
| 23 | * @param array $parts |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function parseContext(array &$context, array $parts) |
|
| 27 | { |
||
| 28 | // Order is important! |
||
| 29 | $params = array_fill_keys(array('action', 'id', 'flag'), null); |
||
| 30 | |||
| 31 | if (isset($parts[2])) { |
||
| 32 | $extras = preg_split('/\//', $parts[2], -1, PREG_SPLIT_NO_EMPTY); |
||
| 33 | list($params['action'], $params['id'], $params['flag']) = $extras; |
||
| 34 | $params['id'] = (int)$params['id']; |
||
| 35 | } |
||
| 36 | |||
| 37 | $context = array_filter($params); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function insertBreadcrumbsUsingPageIdentifier($page_id, $preserve_last = true) |
||
| 41 | { |
||
| 42 | if ($page_id === 0) { |
||
| 43 | return $this->insertBreadcrumbs( |
||
| 44 | array(Widget::Anchor(__('Pages'), SYMPHONY_URL . '/blueprints/pages/')) |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | |||
| 48 | $pages = PageManager::resolvePage($page_id, 'handle'); |
||
| 49 | |||
| 50 | foreach ($pages as &$page) { |
||
|
|
|||
| 51 | // If we are viewing the Page Editor, the Breadcrumbs should link |
||
| 52 | // to the parent's Page Editor. |
||
| 53 | if ($this->_context['action'] === 'edit') { |
||
| 54 | $page = Widget::Anchor( |
||
| 55 | PageManager::fetchTitleFromHandle($page), |
||
| 56 | SYMPHONY_URL . '/blueprints/pages/edit/' . PageManager::fetchIDFromHandle($page) . '/' |
||
| 57 | ); |
||
| 58 | |||
| 59 | // If the pages index is nested, the Breadcrumb should link to the |
||
| 60 | // Pages Index filtered by parent |
||
| 61 | } elseif (Symphony::Configuration()->get('pages_table_nest_children', 'symphony') === 'yes') { |
||
| 62 | $page = Widget::Anchor( |
||
| 63 | PageManager::fetchTitleFromHandle($page), |
||
| 64 | SYMPHONY_URL . '/blueprints/pages/?parent=' . PageManager::fetchIDFromHandle($page) |
||
| 65 | ); |
||
| 66 | |||
| 67 | // If there is no nesting on the Pages Index, the breadcrumb is |
||
| 68 | // not a link, just plain text |
||
| 69 | } else { |
||
| 70 | $page = new XMLElement('span', PageManager::fetchTitleFromHandle($page)); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!$preserve_last) { |
||
| 75 | array_pop($pages); |
||
| 76 | } |
||
| 77 | |||
| 78 | $this->insertBreadcrumbs(array_merge( |
||
| 79 | array(Widget::Anchor(__('Pages'), SYMPHONY_URL . '/blueprints/pages/')), |
||
| 80 | $pages |
||
| 81 | )); |
||
| 82 | } |
||
| 83 | |||
| 84 | public function __viewIndex() |
||
| 85 | { |
||
| 86 | $this->setPageType('table'); |
||
| 87 | $this->setTitle(__('%1$s – %2$s', array(__('Pages'), __('Symphony')))); |
||
| 88 | |||
| 89 | $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') === 'yes'; |
||
| 90 | |||
| 91 | if ($nesting && isset($_GET['parent']) && is_numeric($_GET['parent'])) { |
||
| 92 | $parent = PageManager::fetchPageByID((int)$_GET['parent'], array('title', 'id')); |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->appendSubheading(isset($parent) ? $parent['title'] : __('Pages'), Widget::Anchor( |
||
| 96 | __('Create New'), Administration::instance()->getCurrentPageURL() . 'new/' . ($nesting && isset($parent) ? "?parent={$parent['id']}" : null), |
||
| 97 | __('Create a new page'), 'create button', null, array('accesskey' => 'c') |
||
| 98 | )); |
||
| 99 | |||
| 100 | if (isset($parent)) { |
||
| 101 | $this->insertBreadcrumbsUsingPageIdentifier($parent['id'], false); |
||
| 102 | } |
||
| 103 | |||
| 104 | $aTableHead = array( |
||
| 105 | array(__('Name'), 'col'), |
||
| 106 | array(__('Template'), 'col'), |
||
| 107 | array('<abbr title="' . __('Universal Resource Locator') . '">' . __('URL') . '</abbr>', 'col'), |
||
| 108 | array(__('Parameters'), 'col'), |
||
| 109 | array(__('Type'), 'col') |
||
| 110 | ); |
||
| 111 | $aTableBody = array(); |
||
| 112 | |||
| 113 | if ($nesting) { |
||
| 114 | $aTableHead[] = array(__('Children'), 'col'); |
||
| 115 | $where = array( |
||
| 116 | 'parent ' . (isset($parent) ? " = {$parent['id']} " : ' IS NULL ') |
||
| 117 | ); |
||
| 118 | } else { |
||
| 119 | $where = array(); |
||
| 120 | } |
||
| 121 | |||
| 122 | $pages = PageManager::fetch(true, array('*'), $where); |
||
| 123 | |||
| 124 | if (!is_array($pages) || empty($pages)) { |
||
| 125 | $aTableBody = array(Widget::TableRow(array( |
||
| 126 | Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead)) |
||
| 127 | ), 'odd')); |
||
| 128 | } else { |
||
| 129 | foreach ($pages as $page) { |
||
| 130 | $class = array(); |
||
| 131 | |||
| 132 | $page_title = ($nesting ? $page['title'] : PageManager::resolvePageTitle($page['id'])); |
||
| 133 | $page_url = URL . '/' . PageManager::resolvePagePath($page['id']) . '/'; |
||
| 134 | $page_edit_url = Administration::instance()->getCurrentPageURL() . 'edit/' . $page['id'] . '/'; |
||
| 135 | $page_template = PageManager::createFilePath($page['path'], $page['handle']); |
||
| 136 | |||
| 137 | $col_title = Widget::TableData(Widget::Anchor($page_title, $page_edit_url, $page['handle'])); |
||
| 138 | $col_title->appendChild(Widget::Label(__('Select Page %s', array($page_title)), null, 'accessible', null, array( |
||
| 139 | 'for' => 'page-' . $page['id'] |
||
| 140 | ))); |
||
| 141 | $col_title->appendChild(Widget::Input('items['.$page['id'].']', 'on', 'checkbox', array( |
||
| 142 | 'id' => 'page-' . $page['id'] |
||
| 143 | ))); |
||
| 144 | |||
| 145 | $col_template = Widget::TableData($page_template . '.xsl'); |
||
| 146 | |||
| 147 | $col_url = Widget::TableData(Widget::Anchor($page_url, $page_url)); |
||
| 148 | |||
| 149 | View Code Duplication | if ($page['params']) { |
|
| 150 | $col_params = Widget::TableData(trim($page['params'], '/')); |
||
| 151 | } else { |
||
| 152 | $col_params = Widget::TableData(__('None'), 'inactive'); |
||
| 153 | } |
||
| 154 | |||
| 155 | View Code Duplication | if (!empty($page['type'])) { |
|
| 156 | $col_types = Widget::TableData(implode(', ', $page['type'])); |
||
| 157 | } else { |
||
| 158 | $col_types = Widget::TableData(__('None'), 'inactive'); |
||
| 159 | } |
||
| 160 | |||
| 161 | if (in_array($page['id'], $this->_hilights)) { |
||
| 162 | $class[] = 'failed'; |
||
| 163 | } |
||
| 164 | |||
| 165 | $columns = array($col_title, $col_template, $col_url, $col_params, $col_types); |
||
| 166 | |||
| 167 | if ($nesting) { |
||
| 168 | if (PageManager::hasChildPages($page['id'])) { |
||
| 169 | $col_children = Widget::TableData( |
||
| 170 | Widget::Anchor(PageManager::getChildPagesCount($page['id']) . ' →', |
||
| 171 | SYMPHONY_URL . '/blueprints/pages/?parent=' . $page['id']) |
||
| 172 | ); |
||
| 173 | } else { |
||
| 174 | $col_children = Widget::TableData(__('None'), 'inactive'); |
||
| 175 | } |
||
| 176 | |||
| 177 | $columns[] = $col_children; |
||
| 178 | } |
||
| 179 | |||
| 180 | $aTableBody[] = Widget::TableRow( |
||
| 181 | $columns, |
||
| 182 | implode(' ', $class) |
||
| 183 | ); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | $table = Widget::Table( |
||
| 188 | Widget::TableHead($aTableHead), null, |
||
| 189 | Widget::TableBody($aTableBody), 'orderable selectable', |
||
| 190 | null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive') |
||
| 191 | ); |
||
| 192 | |||
| 193 | $this->Form->appendChild($table); |
||
| 194 | |||
| 195 | $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array( |
||
| 196 | 'id' => 'version' |
||
| 197 | )); |
||
| 198 | $this->Form->appendChild($version); |
||
| 199 | |||
| 200 | $tableActions = new XMLElement('div'); |
||
| 201 | $tableActions->setAttribute('class', 'actions'); |
||
| 202 | |||
| 203 | $options = array( |
||
| 204 | array(null, false, __('With Selected...')), |
||
| 205 | array('delete', false, __('Delete'), 'confirm', null, array( |
||
| 206 | 'data-message' => __('Are you sure you want to delete the selected pages?') |
||
| 207 | )) |
||
| 208 | ); |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Allows an extension to modify the existing options for this page's |
||
| 212 | * With Selected menu. If the `$options` parameter is an empty array, |
||
| 213 | * the 'With Selected' menu will not be rendered. |
||
| 214 | * |
||
| 215 | * @delegate AddCustomActions |
||
| 216 | * @since Symphony 2.3.2 |
||
| 217 | * @param string $context |
||
| 218 | * '/blueprints/pages/' |
||
| 219 | * @param array $options |
||
| 220 | * An array of arrays, where each child array represents an option |
||
| 221 | * in the With Selected menu. Options should follow the same format |
||
| 222 | * expected by `Widget::__SelectBuildOption`. Passed by reference. |
||
| 223 | */ |
||
| 224 | Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/blueprints/pages/', array( |
||
| 225 | 'options' => &$options |
||
| 226 | )); |
||
| 227 | |||
| 228 | if (!empty($options)) { |
||
| 229 | $tableActions->appendChild(Widget::Apply($options)); |
||
| 230 | $this->Form->appendChild($tableActions); |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | public function __viewNew() |
||
| 238 | |||
| 239 | public function __viewEdit() |
||
| 240 | { |
||
| 241 | $this->setPageType('form'); |
||
| 242 | $fields = array("title"=>null, "handle"=>null, "parent"=>null, "params"=>null, "type"=>null, "data_sources"=>null); |
||
| 243 | $existing = $fields; |
||
| 244 | |||
| 245 | $nesting = (Symphony::Configuration()->get('pages_table_nest_children', 'symphony') === 'yes'); |
||
| 246 | |||
| 247 | // Verify page exists: |
||
| 248 | if ($this->_context['action'] === 'edit') { |
||
| 249 | if (!$page_id = (int)$this->_context['id']) { |
||
| 250 | redirect(SYMPHONY_URL . '/blueprints/pages/'); |
||
| 251 | } |
||
| 252 | |||
| 253 | $existing = PageManager::fetchPageByID($page_id); |
||
| 254 | |||
| 255 | if (!$existing) { |
||
| 256 | Administration::instance()->errorPageNotFound(); |
||
| 257 | } else { |
||
| 258 | $existing['type'] = PageManager::fetchPageTypes($page_id); |
||
| 259 | } |
||
| 260 | } |
||
| 261 | |||
| 262 | // Status message: |
||
| 263 | if (isset($this->_context['flag'])) { |
||
| 264 | $flag = $this->_context['flag']; |
||
| 265 | $parent_link_suffix = $message = ''; |
||
| 266 | $time = Widget::Time(); |
||
| 267 | |||
| 268 | if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { |
||
| 269 | $parent_link_suffix = "?parent=" . $_REQUEST['parent']; |
||
| 270 | } elseif ($nesting && isset($existing) && !is_null($existing['parent'])) { |
||
| 271 | $parent_link_suffix = '?parent=' . $existing['parent']; |
||
| 272 | } |
||
| 273 | |||
| 274 | switch ($flag) { |
||
| 275 | case 'saved': |
||
| 276 | $message = __('Page updated at %s.', array($time->generate())); |
||
| 277 | break; |
||
| 278 | case 'created': |
||
| 279 | $message = __('Page created at %s.', array($time->generate())); |
||
| 280 | } |
||
| 281 | |||
| 282 | $this->pageAlert( |
||
| 283 | $message |
||
| 284 | . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/' . $parent_link_suffix . '" accesskey="c">' |
||
| 285 | . __('Create another?') |
||
| 286 | . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">' |
||
| 287 | . __('View all Pages') |
||
| 288 | . '</a>', |
||
| 289 | Alert::SUCCESS |
||
| 290 | ); |
||
| 291 | } |
||
| 292 | |||
| 293 | // Find values: |
||
| 294 | if (isset($_POST['fields'])) { |
||
| 295 | $fields = $_POST['fields']; |
||
| 296 | } elseif ($this->_context['action'] === 'edit') { |
||
| 297 | $fields = $existing; |
||
| 298 | |||
| 299 | if (!is_null($fields['type'])) { |
||
| 300 | $fields['type'] = implode(', ', $fields['type']); |
||
| 301 | } |
||
| 302 | |||
| 303 | $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); |
||
| 304 | $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); |
||
| 305 | View Code Duplication | } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { |
|
| 306 | $fields['parent'] = $_REQUEST['parent']; |
||
| 307 | } |
||
| 308 | |||
| 309 | $title = $fields['title']; |
||
| 310 | |||
| 311 | if (trim($title) === '') { |
||
| 312 | $title = $existing['title']; |
||
| 313 | } |
||
| 314 | |||
| 315 | $this->setTitle(__( |
||
| 316 | ($title ? '%1$s – %2$s – %3$s' : '%2$s – %3$s'), |
||
| 317 | array( |
||
| 318 | $title, |
||
| 319 | __('Pages'), |
||
| 320 | __('Symphony') |
||
| 321 | ) |
||
| 322 | )); |
||
| 323 | |||
| 324 | $page_id = isset($page_id) ? $page_id : null; |
||
| 325 | |||
| 326 | if (!empty($title)) { |
||
| 327 | $page_url = URL . '/' . PageManager::resolvePagePath($page_id) . '/'; |
||
| 328 | |||
| 329 | $this->appendSubheading($title, array( |
||
| 330 | Widget::Anchor(__('View Page'), $page_url, __('View Page on Frontend'), 'button', null, array('target' => '_blank', 'accesskey' => 'v')) |
||
| 331 | )); |
||
| 332 | } else { |
||
| 333 | $this->appendSubheading(!empty($title) ? $title : __('Untitled')); |
||
| 334 | } |
||
| 335 | |||
| 336 | if (isset($page_id)) { |
||
| 337 | $this->insertBreadcrumbsUsingPageIdentifier($page_id, false); |
||
| 338 | } else { |
||
| 339 | $_GET['parent'] = isset($_GET['parent']) ? $_GET['parent'] : null; |
||
| 340 | $this->insertBreadcrumbsUsingPageIdentifier((int)$_GET['parent'], true); |
||
| 341 | } |
||
| 342 | |||
| 343 | // Title -------------------------------------------------------------- |
||
| 344 | |||
| 345 | $fieldset = new XMLElement('fieldset'); |
||
| 346 | $fieldset->setAttribute('class', 'settings'); |
||
| 347 | $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); |
||
| 348 | |||
| 349 | $label = Widget::Label(__('Name')); |
||
| 350 | $label->appendChild(Widget::Input( |
||
| 351 | 'fields[title]', General::sanitize($fields['title']) |
||
| 352 | )); |
||
| 353 | |||
| 354 | if (isset($this->_errors['title'])) { |
||
| 355 | $label = Widget::Error($label, $this->_errors['title']); |
||
| 356 | } |
||
| 357 | |||
| 358 | $fieldset->appendChild($label); |
||
| 359 | |||
| 360 | // Handle ------------------------------------------------------------- |
||
| 361 | |||
| 362 | $group = new XMLElement('div'); |
||
| 363 | $group->setAttribute('class', 'two columns'); |
||
| 364 | $column = new XMLElement('div'); |
||
| 365 | $column->setAttribute('class', 'column'); |
||
| 366 | |||
| 367 | $label = Widget::Label(__('Handle')); |
||
| 368 | $label->appendChild(Widget::Input( |
||
| 369 | 'fields[handle]', $fields['handle'] |
||
| 370 | )); |
||
| 371 | |||
| 372 | if (isset($this->_errors['handle'])) { |
||
| 373 | $label = Widget::Error($label, $this->_errors['handle']); |
||
| 374 | } |
||
| 375 | |||
| 376 | $column->appendChild($label); |
||
| 377 | |||
| 378 | // Parent --------------------------------------------------------- |
||
| 379 | |||
| 380 | $label = Widget::Label(__('Parent Page')); |
||
| 381 | |||
| 382 | $where = array( |
||
| 383 | sprintf('id != %d', $page_id) |
||
| 384 | ); |
||
| 385 | $pages = PageManager::fetch(false, array('id'), $where, 'title ASC'); |
||
| 386 | |||
| 387 | $options = array( |
||
| 388 | array('', false, '/') |
||
| 389 | ); |
||
| 390 | |||
| 391 | if (!empty($pages)) { |
||
| 392 | foreach ($pages as $page) { |
||
| 393 | $options[] = array( |
||
| 394 | $page['id'], $fields['parent'] === $page['id'], |
||
| 395 | '/' . PageManager::resolvePagePath($page['id']) |
||
| 396 | ); |
||
| 397 | } |
||
| 398 | |||
| 399 | usort($options, array($this, '__compare_pages')); |
||
| 400 | } |
||
| 401 | |||
| 402 | $label->appendChild(Widget::Select( |
||
| 403 | 'fields[parent]', $options |
||
| 404 | )); |
||
| 405 | $column->appendChild($label); |
||
| 406 | $group->appendChild($column); |
||
| 407 | |||
| 408 | // Parameters --------------------------------------------------------- |
||
| 409 | |||
| 410 | $column = new XMLElement('div'); |
||
| 411 | $column->setAttribute('class', 'column'); |
||
| 412 | |||
| 413 | $label = Widget::Label(__('Parameters')); |
||
| 414 | $label->appendChild(Widget::Input( |
||
| 415 | 'fields[params]', $fields['params'], 'text', array('placeholder' => 'param1/param2') |
||
| 416 | )); |
||
| 417 | $column->appendChild($label); |
||
| 418 | |||
| 419 | // Type ----------------------------------------------------------- |
||
| 420 | |||
| 421 | $label = Widget::Label(__('Type')); |
||
| 422 | $label->appendChild(Widget::Input('fields[type]', $fields['type'])); |
||
| 423 | |||
| 424 | if (isset($this->_errors['type'])) { |
||
| 425 | $label = Widget::Error($label, $this->_errors['type']); |
||
| 426 | } |
||
| 427 | |||
| 428 | $column->appendChild($label); |
||
| 429 | |||
| 430 | $tags = new XMLElement('ul'); |
||
| 431 | $tags->setAttribute('class', 'tags'); |
||
| 432 | $tags->setAttribute('data-interactive', 'data-interactive'); |
||
| 433 | |||
| 434 | $types = PageManager::fetchAvailablePageTypes(); |
||
| 435 | |||
| 436 | foreach ($types as $type) { |
||
| 437 | $tags->appendChild(new XMLElement('li', $type)); |
||
| 438 | } |
||
| 439 | |||
| 440 | $column->appendChild($tags); |
||
| 441 | $group->appendChild($column); |
||
| 442 | $fieldset->appendChild($group); |
||
| 443 | $this->Form->appendChild($fieldset); |
||
| 444 | |||
| 445 | // Events ------------------------------------------------------------- |
||
| 446 | |||
| 447 | $fieldset = new XMLElement('fieldset'); |
||
| 448 | $fieldset->setAttribute('class', 'settings'); |
||
| 449 | $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); |
||
| 450 | |||
| 451 | $group = new XMLElement('div'); |
||
| 452 | $group->setAttribute('class', 'two columns'); |
||
| 453 | |||
| 454 | $label = Widget::Label(__('Events')); |
||
| 455 | $label->setAttribute('class', 'column'); |
||
| 456 | |||
| 457 | $events = ResourceManager::fetch(ResourceManager::RESOURCE_TYPE_EVENT, array(), array(), 'name ASC'); |
||
| 458 | $options = array(); |
||
| 459 | |||
| 460 | View Code Duplication | if (is_array($events) && !empty($events)) { |
|
| 461 | if (!isset($fields['events'])) { |
||
| 462 | $fields['events'] = array(); |
||
| 463 | } |
||
| 464 | |||
| 465 | foreach ($events as $name => $about) { |
||
| 466 | $options[] = array( |
||
| 467 | $name, in_array($name, $fields['events']), $about['name'] |
||
| 468 | ); |
||
| 469 | } |
||
| 470 | } |
||
| 471 | |||
| 472 | $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); |
||
| 473 | $group->appendChild($label); |
||
| 474 | |||
| 475 | // Data Sources ------------------------------------------------------- |
||
| 476 | |||
| 477 | $label = Widget::Label(__('Data Sources')); |
||
| 478 | $label->setAttribute('class', 'column'); |
||
| 479 | |||
| 480 | $datasources = ResourceManager::fetch(ResourceManager::RESOURCE_TYPE_DS, array(), array(), 'name ASC'); |
||
| 481 | $options = array(); |
||
| 482 | |||
| 483 | View Code Duplication | if (is_array($datasources) && !empty($datasources)) { |
|
| 484 | if (!isset($fields['data_sources'])) { |
||
| 485 | $fields['data_sources'] = array(); |
||
| 486 | } |
||
| 487 | |||
| 488 | foreach ($datasources as $name => $about) { |
||
| 489 | $options[] = array( |
||
| 490 | $name, in_array($name, $fields['data_sources']), $about['name'] |
||
| 491 | ); |
||
| 492 | } |
||
| 493 | } |
||
| 494 | |||
| 495 | $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); |
||
| 496 | $group->appendChild($label); |
||
| 497 | $fieldset->appendChild($group); |
||
| 498 | $this->Form->appendChild($fieldset); |
||
| 499 | |||
| 500 | // Controls ----------------------------------------------------------- |
||
| 501 | |||
| 502 | /** |
||
| 503 | * After all Page related Fields have been added to the DOM, just before the |
||
| 504 | * actions. |
||
| 505 | * |
||
| 506 | * @delegate AppendPageContent |
||
| 507 | * @param string $context |
||
| 508 | * '/blueprints/pages/' |
||
| 509 | * @param XMLElement $form |
||
| 510 | * @param array $fields |
||
| 511 | * @param array $errors |
||
| 512 | */ |
||
| 513 | Symphony::ExtensionManager()->notifyMembers( |
||
| 514 | 'AppendPageContent', |
||
| 515 | '/blueprints/pages/', |
||
| 516 | array( |
||
| 517 | 'form' => &$this->Form, |
||
| 518 | 'fields' => &$fields, |
||
| 519 | 'errors' => $this->_errors |
||
| 520 | ) |
||
| 521 | ); |
||
| 522 | |||
| 523 | $div = new XMLElement('div'); |
||
| 524 | $div->setAttribute('class', 'actions'); |
||
| 525 | $div->appendChild(Widget::Input( |
||
| 526 | 'action[save]', ($this->_context['action'] === 'edit' ? __('Save Changes') : __('Create Page')), |
||
| 527 | 'submit', array('accesskey' => 's') |
||
| 528 | )); |
||
| 529 | |||
| 530 | View Code Duplication | if ($this->_context['action'] === 'edit') { |
|
| 531 | $button = new XMLElement('button', __('Delete')); |
||
| 532 | $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?'))); |
||
| 533 | $div->appendChild($button); |
||
| 534 | } |
||
| 535 | |||
| 536 | $this->Form->appendChild($div); |
||
| 537 | |||
| 538 | if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { |
||
| 539 | $this->Form->appendChild(new XMLElement('input', null, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent']))); |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | public function __compare_pages($a, $b) |
||
| 547 | |||
| 548 | public function __actionIndex() |
||
| 577 | |||
| 578 | public function __actionNew() |
||
| 579 | { |
||
| 580 | $this->__actionEdit(); |
||
| 581 | } |
||
| 582 | |||
| 583 | public function __actionEdit() |
||
| 861 | |||
| 862 | public function __actionDelete($pages, $redirect) |
||
| 943 | } |
||
| 944 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.