You are here

function flag_entity_info in Flag 7.3

Implements hook_entity_info().

File

./flag.module, line 16
The Flag module.

Code

function flag_entity_info() {
  $return = array(
    'flagging' => array(
      'label' => t('Flagging'),
      'controller class' => 'FlaggingController',
      'base table' => 'flagging',
      'fieldable' => TRUE,
      'entity keys' => array(
        'id' => 'flagging_id',
        'bundle' => 'flag_name',
      ),
      // The following tells Field UI how to extract the bundle name from a
      // $flag object when we're visiting ?q=admin/.../manage/%flag/fields.
      'bundle keys' => array(
        'bundle' => 'name',
      ),
      'bundles' => array(),
      // The following tells EntityAPI how to save flaggings, thus allowing use
      // of Entity metadata wrappers (if present).
      'save callback' => 'flagging_save',
      'creation callback' => 'flagging_create',
    ),
  );

  // Check for our table before we query it. This is a workaround for a core
  // bug: https://www.drupal.org/node/1311820
  // TODO: Remove this when that bug is fixed.
  if (db_table_exists('flag')) {

    // Add bundle info but bypass flag_get_flags() as we cannot use it here, as
    // it calls entity_get_info().
    $result = db_query("SELECT name, title FROM {flag}");
    $flag_names = $result
      ->fetchAllKeyed();
    foreach ($flag_names as $flag_name => $flag_title) {
      $return['flagging']['bundles'][$flag_name] = array(
        'label' => $flag_title,
        'admin' => array(
          'path' => FLAG_ADMIN_PATH . '/manage/%flag',
          'real path' => FLAG_ADMIN_PATH . '/manage/' . $flag_name,
          'bundle argument' => FLAG_ADMIN_PATH_START + 1,
          'access arguments' => array(
            'administer flags',
          ),
        ),
      );
    }
  }
  return $return;
}