diff --git a/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php b/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php index bfd07ba..fe04982 100644 --- a/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php +++ b/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php @@ -24,6 +24,7 @@ use Drupal\Core\Annotation\Translation; * form_controller_class = { * "default" = "Drupal\profile2\ProfileFormController" * }, + * render_controller_class = "Drupal\Core\Entity\EntityRenderController", * base_table = "profile", * uri_callback = "profile2_profile_uri", * fieldable = TRUE, diff --git a/lib/Drupal/profile2/ProfileTypeFormController.php b/lib/Drupal/profile2/ProfileTypeFormController.php index 0bdf5dd..8a4e924 100644 --- a/lib/Drupal/profile2/ProfileTypeFormController.php +++ b/lib/Drupal/profile2/ProfileTypeFormController.php @@ -37,7 +37,7 @@ class ProfileTypeFormController extends EntityFormController { ); $form['registration'] = array( '#type' => 'checkbox', - '#title' => t('Show during user account registration.'), + '#title' => t('Include in user registration form'), '#default_value' => $type->get('registration'), ); return $form; diff --git a/lib/Drupal/profile2/ProfileTypeListController.php b/lib/Drupal/profile2/ProfileTypeListController.php index d21f713..a94c0a4 100644 --- a/lib/Drupal/profile2/ProfileTypeListController.php +++ b/lib/Drupal/profile2/ProfileTypeListController.php @@ -16,23 +16,47 @@ use Drupal\Core\Entity\EntityInterface; class ProfileTypeListController extends ConfigEntityListController { /** + * Overrides \Drupal\Core\Entity\EntityListController::buildHeader(). + */ + public function buildHeader() { + $row = parent::buildHeader(); + $operations = array_pop($row); + $row['registration'] = t('Registration'); + $row['operations'] = $operations; + return $row; + } + + /** + * Overrides \Drupal\Core\Entity\EntityListController::buildRow(). + */ + public function buildRow(EntityInterface $entity) { + $row = parent::buildRow($entity); + $operations = array_pop($row); + $row['registration'] = $entity->get('registration') ? t('Yes') : t('No'); + $row['operations'] = $operations; + return $row; + } + + /** * Overrides \Drupal\Core\Entity\EntityListController::getOperations(). */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); if (module_exists('field_ui')) { + // Unlike other bundle entities, the most common operation for profile + // types is to manage fields, so we suggest that as default operation. $uri = $entity->uri(); $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'href' => $uri['path'] . '/fields', 'options' => $uri['options'], - 'weight' => 11, + 'weight' => 5, ); $operations['manage-display'] = array( 'title' => t('Manage display'), 'href' => $uri['path'] . '/display', 'options' => $uri['options'], - 'weight' => 12, + 'weight' => 6, ); } return $operations; diff --git a/profile2.info b/profile2.info index 046076d..e3b48f4 100644 --- a/profile2.info +++ b/profile2.info @@ -1,6 +1,8 @@ -name = Profile2 +name = Profile description = Provides configurable user profiles. +package = Core core = 8.x +version = VERSION configure = admin/people/profiles dependencies[] = user dependencies[] = field diff --git a/profile2.module b/profile2.module index 7d52e32..adaf6e0 100644 --- a/profile2.module +++ b/profile2.module @@ -90,7 +90,6 @@ function profile2_menu() { $items['admin/people/profiles/manage/%profile2_type/edit'] = array( 'title' => 'Edit', 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, ); $items['admin/people/profiles/manage/%profile2_type/delete'] = array( 'title' => 'Delete', @@ -98,6 +97,7 @@ function profile2_menu() { 'page arguments' => array('profile2_type_delete_form', 4), 'access arguments' => array('administer profile types'), 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_INLINE, 'file' => 'profile2.admin.inc', ); @@ -105,7 +105,6 @@ function profile2_menu() { $items['user/%user/edit/account'] = array( 'title' => 'Account', 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, ); $items['user/%user/edit/%profile2_menu_arg'] = array( // @see http://drupal.org/node/1863502 @@ -179,15 +178,15 @@ function profile2_menu_arg_load($type_id, $map, $op = '') { } /** - * Implements hook_menu_local_tasks_alter(). + * Implements hook_menu_local_tasks(). */ -function profile2_menu_local_tasks_alter(&$data, $router_item, $root_path) { +function profile2_menu_local_tasks(&$data, $router_item, $root_path) { if ($root_path === 'user/%/edit' || $root_path === 'user/%/edit/%') { - $tabs = &$data['tabs'][1]['output']; + $tabs = &$data['tabs'][1]; // Determine the currently selected tab, if any. $selected_index = -1; $selected_id = ''; - foreach ($tabs as $index => &$tab) { + foreach ($tabs as $index => $tab) { if (isset($tab['#link']['path']) && $tab['#link']['path'] == 'user/%/edit/%') { $selected_index = $index; $selected_id = $router_item['original_map'][3]; @@ -196,6 +195,10 @@ function profile2_menu_local_tasks_alter(&$data, $router_item, $root_path) { // Expand the dynamic %profile_menu argument into a tab for each type. $types = entity_load_multiple('profile2_type'); foreach ($types as $type) { + // Do not expose profile types that do not have any fields attached yet. + if (!field_info_instances('profile2', $type->id())) { + continue; + } // If the current page is the active tab registered in hook_menu(), then // the menu router item with the dynamic argument will be exposed already. // We must not duplicate that tab, but in order to ensure that all of our @@ -211,14 +214,10 @@ function profile2_menu_local_tasks_alter(&$data, $router_item, $root_path) { '#theme' => 'menu_local_task', '#link' => array( 'title' => $type->label(), - 'href' => 'user/' . $router_item['original_map'][1] . '/edit/' . $type->id(), - 'localized_options' => array('html' => FALSE), + 'href' => $router_item['tab_root_href'] . '/edit/' . $type->id(), ), ); } - if ($types) { - $data['tabs'][1]['count']++; - } } }