Would be nice if commons fields (like Radioactivity and Follow) offer a way to disable them on existing features.

For instance, take the Poll module:

<?php/**
 * Implements hook_commons_entity_integration.
 */
function commons_polls_commons_entity_integration() {
  return array(
    'node' => array(
      'poll' => array(
      ),
    ),
  );
}}?>

Currently, there is no way to change this to the following without changing the module:

<?php/**
 * Implements hook_commons_entity_integration.
 */
function commons_polls_commons_entity_integration() {
  return array(
    'node' => array(
      'poll' => array(
        'exclude_commons_follow' => TRUE,
      ),
    ),
  );
}?>

This could be achieved by giving modules the change to alter the hook_commons_entity_integration outcome by changing this:

<?php
function commons_follow_flag_alter(&$flag) {
  $commons_entity_integrations = module_invoke_all('commons_entity_integration');
  ...
}
?>

to

<?php
function commons_follow_flag_alter(&$flag) {
  $commons_entity_integrations = module_invoke_all('commons_entity_integration');
  drupal_alter('commons_entity_integration', $commons_entity_integrations);
  ...
}
?>
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

Here's a first stab. I've introduced a helper function in commons_misc so not all submodules have to implement the alter themselves.

This enables us to change implementations by adding a function like this:

<?php
function MYMODULE_commons_entity_integration_alter(&$commons_entity_integrations) {
  $commons_entity_integrations['node']['event']['exclude_rate'] = TRUE;
}
?>
BarisW’s picture

Version: » 7.x-3.2

Bump.

mpaler’s picture

What's the status with this code proposal? Has it gained any traction? Has an alternative method taken hold?

Specifically, I'm looking for a way to groups integration/requirement for a commons integrated custom content type.

Mike

Devin Carlson’s picture

Version: 7.x-3.2 » 7.x-3.x-dev
Issue summary: View changes
FileSize
11.29 KB

Thanks for the patch!

Attached is an updated patch that:

  • Moves the function into the Commons profile.
  • Adds the ability to return information for a specific entity type.
  • Statically caches the altered results for improved performance.
  • Documents the function parameters and return values.
  • Adds documentation for the existing hook and the new alter function in a new commons.api.php file.
ezra-g’s picture

The approach in #4 looks solid to me. Thanks, Devin Carlson!

Devin Carlson’s picture

Status: Needs review » Fixed

Tested #4 with both a fresh and an existing Commons install and didn't run into any errors or issues with entity integrations not functioning. I was also able to alter existing integrations by implementing the new alter hook.

Committed #4 to Commons 7.x-3.x.

http://drupalcode.org/project/commons.git/commit/4237275

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.