diff --git a/core/modules/page/config/page.front_page.yml b/core/modules/page/config/page.front_page.yml index 9c7d932..7562328 100644 --- a/core/modules/page/config/page.front_page.yml +++ b/core/modules/page/config/page.front_page.yml @@ -5,3 +5,4 @@ visibility: '1' paths: '' layout: 'static_layout:page__complex' langcode: und +weight: 1 diff --git a/core/modules/page/config/page.not_admin_page.yml b/core/modules/page/config/page.not_admin_page.yml index 4985493..c7d1032 100644 --- a/core/modules/page/config/page.not_admin_page.yml +++ b/core/modules/page/config/page.not_admin_page.yml @@ -5,3 +5,4 @@ visibility: '0' paths: "admin\r\nadmin/*" layout: 'static_layout:page__simple' langcode: und +weight: 10 diff --git a/core/modules/page/config/page.user_page.yml b/core/modules/page/config/page.user_page.yml index 19e342f..ce86333 100644 --- a/core/modules/page/config/page.user_page.yml +++ b/core/modules/page/config/page.user_page.yml @@ -5,3 +5,4 @@ visibility: '1' paths: "user\r\nuser/*" layout: 'static_layout:page__complex' langcode: und +weight: 5 diff --git a/core/modules/page/lib/Drupal/page/Page.php b/core/modules/page/lib/Drupal/page/Page.php index 21a71e3..bfd835c 100644 --- a/core/modules/page/lib/Drupal/page/Page.php +++ b/core/modules/page/lib/Drupal/page/Page.php @@ -38,22 +38,29 @@ class Page extends ConfigEntityBase { /** * Whether to apply the path patterns or exclude them. * - * @var $int + * @var int */ public $visibility; /** * Path pattern associated with this page. * - * @var $string + * @var string */ public $paths; /** * Layout machine name associated with this page. * - * @var $string + * @var string */ public $layout; + /** + * Page weight to help figure out priority ordering. + * + * @var int + */ + public $weight; + } diff --git a/core/modules/page/lib/Drupal/page/PageListController.php b/core/modules/page/lib/Drupal/page/PageListController.php index a6e91d5..418c10b 100644 --- a/core/modules/page/lib/Drupal/page/PageListController.php +++ b/core/modules/page/lib/Drupal/page/PageListController.php @@ -24,32 +24,57 @@ public function __construct($entity_type, EntityStorageControllerInterface $stor } /** - * Overrides Drupal\Core\Entity\EntityListController::buildHeader(); - * - * Replace machine name with paths. + * Get form for listing page to display for weights. */ - public function buildHeader() { - $row['label'] = t('Label'); - $row['paths'] = t('Paths'); - $row['operations'] = t('Operations'); - return $row; + public function getForm($form, &$form_state) { + $form['items'] = array( + '#tree' => TRUE, + ); + foreach ($this->load() as $entity) { + $form['items'][$entity->id()]['label'] = array( + '#markup' => check_plain($entity->label()), + ); + + $paths = nl2br(check_plain($entity->paths)); + if (empty($entity->visibility)) { + $paths = t('Except: !paths', array('!paths' => '
' . $paths)); + } + $form['items'][$entity->id()]['paths'] = array( + '#markup' => $paths, + ); + + $form['items'][$entity->id()]['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight'), + '#default_value' => $entity->weight, + '#delta' => 100, + '#attributes' => array('class' => array('entity-weight')), + ); + + $form['items'][$entity->id()]['operations'] = array( + $this->buildOperations($entity), + ); + } + + $form['actions'] = array(); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save changes') + ); + return $form; } /** - * Overrides Drupal\Core\Entity\EntityListController::buildRow(); - * - * Replace machine name with paths. + * Save weight changes to configuration entities. */ - public function buildRow(EntityInterface $entity) { - $row['label'] = $entity->label(); - $paths = nl2br(check_plain($entity->paths)); - if (empty($entity->visibility)) { - $paths = t('Except: !paths', array('!paths' => '
' . $paths)); + public function submitForm($form, &$form_state) { + foreach ($form_state['values']['items'] as $id => $item) { + $page = entity_load('page', $id); + $page->weight = $item['weight']; + var_dump($pagea); + $page->save(); } - $row['paths'] = $paths; - $operations = $this->buildOperations($entity); - $row['operations']['data'] = $operations; - return $row; + exit; } } diff --git a/core/modules/page/page.admin.inc b/core/modules/page/page.admin.inc index 16c4d86..5ac414d 100644 --- a/core/modules/page/page.admin.inc +++ b/core/modules/page/page.admin.inc @@ -13,8 +13,24 @@ * @see page_menu() */ function page_page_list() { + return drupal_get_form('page_page_list_form'); +} + +/** + * Form callback to present a tabledrag list. + */ +function page_page_list_form($form, &$form_state) { + $controller = entity_list_controller('page'); + return $controller->getForm($form, $form_state); +} + + +/** + * Form callback to save a tabledrag list. + */ +function page_page_list_form_submit($form, &$form_state) { $controller = entity_list_controller('page'); - return $controller->render(); + return $controller->submitForm($form, $form_state); } /** @@ -65,3 +81,40 @@ function page_delete_confirm_submit($form, &$form_state) { watchdog('page', 'Page %label has been deleted.', array('%label' => $page->label()), WATCHDOG_NOTICE); $form_state['redirect'] = 'admin/structure/pages'; } + +/** + * Theme callback for page listing form. + */ +function theme_page_page_list_form($variables) { + $form = $variables['form']; + $rows = array(); + + foreach (element_children($form['items'], TRUE) as $id) { + $rows[] = array( + 'data' => array( + drupal_render($form['items'][$id]['label']), + drupal_render($form['items'][$id]['paths']), + drupal_render($form['items'][$id]['weight']), + drupal_render($form['items'][$id]['operations']), + ), + 'class' => array('draggable'), + ); + } + + $header = array( + t('Label'), + t('Paths'), + t('Weight'), + t('Operations'), + ); + + $variables = array( + 'header' => $header, + 'rows' => $rows, + 'attributes' => array('id' => 'page-list'), + ); + $table = theme('table', $variables); + $table .= drupal_render_children($form); + drupal_add_tabledrag('page-list', 'order', 'sibling', 'entity-weight'); + return $table; +} diff --git a/core/modules/page/page.module b/core/modules/page/page.module index c7c0f8e..695e493 100644 --- a/core/modules/page/page.module +++ b/core/modules/page/page.module @@ -162,3 +162,15 @@ function page_load($id) { function page_load_all() { return entity_load_multiple('page'); } + +/** + * Implements hook_theme(). + */ +function page_theme($existing, $type, $theme, $path) { + return array( + 'page_page_list_form' => array( + 'render element' => 'form', + 'file' => 'page.admin.inc', + ), + ); +}