The dropdown on the homepage works fine for default Commons node types but might go wrong for extra node types.
See screenshot: gallerys? group informations?

commons-dropdown.png

Any ideas on how to fix this? Maybe check the last letter to see if we need to add an s?

CommentFileSizeAuthor
commons-dropdown.png23.9 KBBarisW

Comments

BarisW’s picture

After some thinking I believe that the most fool-proof way of handling this is to add the plural name to either the node type definition (as field) or using the hook_commons_entity_integration() like this:

<?php
/**
 * Implements hook_commons_entity_integration.
 */
function commons_posts_commons_entity_integration() {
  return array(
    'node' => array(
      'post' => array(
        'plural' => 'posts',
      ),
    ),
  );
}
?>

Then we can change this

<?php
    foreach ($form['type']['#options'] as $type => $name) {
      if ($type != 'All') {
        $form['type']['#options'][$type] = t(strtolower(substr($name, 0, 1)) . substr($name,1) . 's');
      }
    }
?>

to

<?php
    $commons_integrations = module_invoke_all('commons_entity_integration');
    foreach ($form['type']['#options'] as $type => $name) {
      if ($type != 'All') {
        if (isset($commons_integrations['node'][$type]['plural'])) {
          $newname = $commons_integrations['node'][$type]['plural'];
        }
        else {
          $newname = strtolower(substr($name, 0, 1)) . substr($name,1) . 's';
        }
        $form['type']['#options'][$type] = t($newname);
      }
    }
?>
BarisW’s picture

The last piece of code can even be a bit clearer by rewriting the strtolower logic:

<?php
    $commons_integrations = module_invoke_all('commons_entity_integration');
    foreach ($form['type']['#options'] as $type => $name) {
      if ($type != 'All') {
        if (isset($commons_integrations['node'][$type]['plural'])) {
          $newname = $commons_integrations['node'][$type]['plural'];
        }
        else {
          $newname = $name . 's';
        }
        $form['type']['#options'][$type] = strtolower(t($newname));
      }
    }
?>
lsolesen’s picture

Version: » 7.x-3.x-dev
Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

Can you create a patch?