commit c8b6c09c4195bda8338b5ce0639690d62222bc60 Author: Lee Rowlands Date: Thu May 16 20:03:21 2013 +1000 Fixes issues with menu tabs diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 66da884..79f1314 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -9,87 +9,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * Page callback: Displays the comment bundle admin overview page. - */ -function comment_overview_bundles() { - $header = array( - 'field_name' => t('Field name'), - 'usage' => array( - 'data' => t('Used in'), - 'class' => array(RESPONSIVE_PRIORITY_MEDIUM), - ), - ); - - $field_ui = module_exists('field_ui'); - if ($field_ui) { - $header['operations'] = t('Operations'); - } - - $entity_bundles = entity_get_bundles(); - $entity_types = drupal_container()->get('plugin.manager.entity')->getDefinitions(); - $rows = array(); - - foreach (comment_get_comment_fields() as $field_name => $field_info_map) { - $field_info = field_info_field($field_name); - // Initialize the row. - $rows[$field_name]['class'] = $field_info['locked'] ? array('field-disabled') : array(''); - $rows[$field_name]['data']['field_name']['data'] = $field_info['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name; - - $rows[$field_name]['data']['usage']['data'] = array( - '#theme' => 'item_list', - '#items' => array(), - ); - foreach ($field_info['bundles'] as $entity_type => $field_bundles) { - $bundles = array(); - foreach ($field_bundles as $bundle) { - if (isset($entity_bundles[$entity_type][$bundle])) { - // Add the current instance. - if ($field_ui && $path = field_ui_bundle_admin_path($entity_type, $bundle)) { - $bundles[] = l($entity_bundles[$entity_type][$bundle]['label'], $path . '/fields'); - } - else { - $bundles[] = $entity_bundles[$entity_type][$bundle]['label']; - } - } - } - // Format used entity bundles. - $rows[$field_name]['data']['usage']['data']['#items'][] = t('@entity_type: !bundles', array( - '@entity_type' => $entity_types[$entity_type]['label'], - '!bundles' => implode(', ', $bundles), - )); - } - - if ($field_ui) { - // @todo Check proper permissions for operations. - $links['fields'] = array( - 'title' => t('manage fields'), - 'href' => 'admin/structure/comments/' . $field_name . '/fields', - 'weight' => 5, - ); - $links['display'] = array( - 'title' => t('manage display'), - 'href' => 'admin/structure/comments/' . $field_name . '/display', - 'weight' => 10, - ); - - $rows[$field_name]['data']['operations']['data'] = array( - '#type' => 'operations', - '#links' => $links, - ); - } - } - - $build['overview'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No comment forms available.'), - ); - - return $build; -} - -/** * Page callback: Presents an administrative comment listing. * * @param $type diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 1d6b092..f54c901 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -560,7 +560,7 @@ function comment_update_8006(&$sandbox) { $node_types = array_keys(_update_7000_node_get_types()); foreach ($node_types as $node_type) { // COMMENT_OPEN - $default_value = variable_get('comment_' . $node_type, 2); + $default_value = update_variable_get('comment_' . $node_type, 2); // Add a default comment field for existing node comments. $field = array( 'cardinality' => '1', @@ -572,44 +572,57 @@ function comment_update_8006(&$sandbox) { 'type' => 'comment', ); // Make sure field doesn't already exist. - if (!_update_7000_field_read_fields(array('field_name' => $field['field_name']))) { - // Create the field. - _update_7000_field_create_field($field); + $original_name = $field['field_name']; + $index = 0; + while (_update_7000_field_read_fields(array('field_name' => $field['field_name']))) { + // Append a numeric index. + $field['field_name'] = $original_name . '_' . $index; + // Increment index. + $index++; + } + _update_7000_field_create_field($field); + + $existing_instance = db_select('field_config_instance', 'f') + ->condition('field_name', $field['field_name']) + ->condition('bundle', $node_type) + ->condition('entity_type', 'node') + ->execute() + ->fetch(); + if (!$existing_instance) { + // Add the comment field, setting the instance settings to match those for + // the given node_type. + $instance_settings = array( + // COMMENT_MODE_THREADED + 'default_mode' => update_variable_get('comment_default_mode_' . $node_type, 1), + 'per_page' => update_variable_get('comment_default_per_page_' . $node_type, 50), + // COMMENT_FORM_BELOW + 'form_location' => update_variable_get('comment_form_location' . $node_type, 1), + // COMMENT_ANONYMOUS_MAYNOT_CONTACT + 'anonymous' => update_variable_get('comment_anonymous_' . $node_type, 0), + 'subject' => update_variable_get('comment_subject_field_' . $node_type, 1), + // DRUPAL_OPTIONAL + 'preview' => update_variable_get('comment_preview_' . $node_type, 1), + ); + $instance = array( + 'bundle' => $node_type, + 'default_value' => array(array('status' => $default_value)), + 'deleted' => '0', + 'description' => '', + 'entity_type' => 'node', + 'field_name' => $field['field_name'], + 'label' => 'Comment settings', + 'required' => 1, + 'settings' => $instance_settings, + 'widget' => array( + 'active' => 0, + 'module' => 'comment', + 'settings' => array(), + 'type' => 'comment_default', + 'weight' => '50', + ), + ); + _update_7000_field_create_instance($field, $instance); } - - // Add the comment field, setting the instance settings to match those for - // the given node_type. - $instance_settings = array( - // COMMENT_MODE_THREADED - 'default_mode' => variable_get('comment_default_mode_' . $node_type, 1), - 'per_page' => variable_get('comment_default_per_page_' . $node_type, 50), - // COMMENT_FORM_BELOW - 'form_location' => variable_get('comment_form_location' . $node_type, 1), - // COMMENT_ANONYMOUS_MAYNOT_CONTACT - 'anonymous' => variable_get('comment_anonymous_' . $node_type, 0), - 'subject' => variable_get('comment_subject_field_' . $node_type, 1), - // DRUPAL_OPTIONAL - 'preview' => variable_get('comment_preview_' . $node_type, 1), - ); - $instance = array( - 'bundle' => $node_type, - 'default_value' => array(array('status' => $default_value)), - 'deleted' => '0', - 'description' => '', - 'entity_type' => 'node', - 'field_name' => $field['field_name'], - 'label' => 'Comment settings', - 'required' => 1, - 'settings' => $instance_settings, - 'widget' => array( - 'active' => 0, - 'module' => 'comment', - 'settings' => array(), - 'type' => 'comment_default', - 'weight' => '50', - ), - ); - _update_7000_field_create_instance($field, $instance); // Prepare defaults for the default and full view modes. $display_options_default = array( diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index c7eed83..ff8960c 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -350,9 +350,7 @@ function comment_menu() { $items['admin/structure/comments'] = array( 'title' => 'Comment forms', 'description' => 'Manage fields and displays settings for comment forms.', - 'page callback' => 'comment_overview_bundles', - 'access arguments' => array('administer comments'), - 'file' => 'comment.admin.inc', + 'route_name' => 'comment_overview_bundles', ); $items['admin/content/comment'] = array( 'title' => 'Comments', @@ -1040,6 +1038,22 @@ function comment_form_field_ui_field_edit_form_alter(&$form, $form_state) { } /** + * Implements hook_form_FORM_ID_alter() for field_ui_field_overview_form(). + */ +function comment_form_field_ui_field_overview_form_alter(&$form, $form_state) { + // @todo Remove when http://drupal.org/node/1981644 is in. + drupal_set_title(t('Manage Fields: %field_name', array('%field_name' => $form['#bundle'])), TRUE); +} + +/** + * Implements hook_form_FORM_ID_alter() for field_ui_display_overview_form(). + */ +function comment_form_field_ui_display_overview_form_alter(&$form, $form_state) { + // @todo Remove when http://drupal.org/node/1981644 is in. + drupal_set_title(t('Manage Display: %field_name', array('%field_name' => $form['#bundle'])), TRUE); +} + +/** * Implements hook_form_FORM_ID_alter() for field_ui_field_settings_form(). */ function comment_form_field_ui_field_settings_form_alter(&$form, $form_state) { diff --git a/core/modules/comment/comment.routing.yml b/core/modules/comment/comment.routing.yml index 6f786dd..ac90358 100644 --- a/core/modules/comment/comment.routing.yml +++ b/core/modules/comment/comment.routing.yml @@ -1,7 +1,13 @@ comment_edit_page: - pattern: 'comment/{comment}/edit' - defaults: - _entity_form: comment.default - requirements: - _entity_access: comment.update - + pattern: '/comment/{comment}/edit' + defaults: + _entity_form: 'comment.default' + requirements: + _entity_access: 'comment.update' +comment_overview_bundles: + pattern: '/admin/structure/comments/{bundle}' + defaults: + _content: 'Drupal\comment\Controller\AdminController::overviewBundles' + bundle: NULL + requirements: + _permission: 'administer comments' diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php new file mode 100644 index 0000000..63552b3 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php @@ -0,0 +1,156 @@ +get('plugin.manager.entity'), + $container->get('module_handler'), + $container->get('field.info') + ); + } + + /** + * Constructs a CustomBlock object. + * + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * Entity manager service. + * @param \Drupal\Core\Extension\ModuleHandler $module_handler + * Module Handler service. + * @param \Drupal\field\FieldInfo $field_info + * Field Info service. + */ + public function __construct(EntityManager $entity_manager, ModuleHandler $module_handler, FieldInfo $field_info) { + $this->entityManager = $entity_manager; + $this->moduleHandler = $module_handler; + $this->fieldInfo = $field_info; + } + + /** + * Returns markup for the overview of comment bundles. + */ + public function overviewBundles() { + // @todo Remove when http://drupal.org/node/1981644 is in. + drupal_set_title(t('Comment forms')); + $header = array( + 'field_name' => t('Field name'), + 'usage' => array( + 'data' => t('Used in'), + 'class' => array(RESPONSIVE_PRIORITY_MEDIUM), + ), + ); + + $field_ui = $this->moduleHandler->moduleExists('field_ui'); + if ($field_ui) { + $header['operations'] = t('Operations'); + } + + // @todo remove when entity_get_bundles() is a method on the entity manager. + $entity_bundles = entity_get_bundles(); + $entity_types = $this->entityManager->getDefinitions(); + $rows = array(); + + $fields = array_filter($this->fieldInfo->getFieldMap(), function ($value) { + if ($value['type'] == 'comment') { + return TRUE; + } + }); + + foreach ($fields as $field_name => $field_info_map) { + $field_info = $this->fieldInfo->getField($field_name); + // Initialize the row. + $rows[$field_name]['class'] = $field_info['locked'] ? array('field-disabled') : array(''); + $rows[$field_name]['data']['field_name']['data'] = $field_info['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name; + + $rows[$field_name]['data']['usage']['data'] = array( + '#theme' => 'item_list', + '#items' => array(), + ); + foreach ($field_info['bundles'] as $entity_type => $field_bundles) { + $bundles = array(); + foreach ($field_bundles as $bundle) { + if (isset($entity_bundles[$entity_type][$bundle])) { + // Add the current instance. + if ($field_ui && ($path = $this->entityManager->getAdminPath($entity_type, $bundle))) { + $bundles[] = l($entity_bundles[$entity_type][$bundle]['label'], $path . '/fields'); + } + else { + $bundles[] = $entity_bundles[$entity_type][$bundle]['label']; + } + } + } + // Format used entity bundles. + $rows[$field_name]['data']['usage']['data']['#items'][] = t('@entity_type: !bundles', array( + '@entity_type' => $entity_types[$entity_type]['label'], + '!bundles' => implode(', ', $bundles), + )); + } + + if ($field_ui) { + // @todo Check proper permissions for operations. + $links['fields'] = array( + 'title' => t('manage fields'), + 'href' => 'admin/structure/comments/' . $field_name . '/fields', + 'weight' => 5, + ); + $links['display'] = array( + 'title' => t('manage display'), + 'href' => 'admin/structure/comments/' . $field_name . '/display', + 'weight' => 10, + ); + + $rows[$field_name]['data']['operations']['data'] = array( + '#type' => 'operations', + '#links' => $links, + ); + } + } + + $build['overview'] = array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + '#empty' => t('No comment forms available.'), + ); + + return $build; + } + +} diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php index 1ebe94d..8652da2 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php @@ -34,7 +34,6 @@ * fieldable = TRUE, * translatable = TRUE, * route_base_path = "admin/structure/comments/{bundle}", - * bundle_prefix = "", * entity_keys = { * "id" = "cid", * "bundle" = "field_name", diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentApprovalTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php similarity index 87% rename from core/modules/comment/lib/Drupal/comment/Tests/CommentApprovalTest.php rename to core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php index 3662a01..3ef20ec 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentApprovalTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\comment\Tests\CommentApprovalTest. + * Definition of Drupal\comment\Tests\CommentAdminTest. */ namespace Drupal\comment\Tests; @@ -10,11 +10,11 @@ /** * Tests comment approval functionality. */ -class CommentApprovalTest extends CommentTestBase { +class CommentAdminTest extends CommentTestBase { public static function getInfo() { return array( - 'name' => 'Comment approval', - 'description' => 'Test comment approval functionality.', + 'name' => 'Comment admin', + 'description' => 'Test comment admin functionality.', 'group' => 'Comment', ); } @@ -143,4 +143,25 @@ function testApprovalNodeInterface() { $this->drupalGet('node/' . $this->node->nid); $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.'); } + + /** + * Tests comment bundle admin. + */ + public function testCommentAdmin() { + // Login. + $this->drupalLogin($this->admin_user); + // Browse to comment bundle overview. + $this->drupalGet('admin/structure/comments'); + $this->assertResponse(200); + // Make sure titles visible. + $this->assertText('Field name'); + $this->assertText('Used in'); + // Manage fields. + $this->clickLink('manage fields'); + $this->assertResponse(200); + // Make sure field is shown. + $this->assertText('Title'); + // Rest from here on in is field_ui. + } + } commit b78731ff49da8d2337f45dd9e1a0639a13c6194b Author: Lee Rowlands Date: Thu May 16 20:19:21 2013 +1000 Text fixes diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php index 3ef20ec..2bcfecb 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php @@ -159,8 +159,10 @@ public function testCommentAdmin() { // Manage fields. $this->clickLink('manage fields'); $this->assertResponse(200); - // Make sure field is shown. - $this->assertText('Title'); + // Make sure title is correctly set. + $this->assertText('Manage Fields: comment'); + // Make sure subject field is shown. + $this->assertText('Subject'); // Rest from here on in is field_ui. }