0

I am in learning phase of Drupal and ofcourse the Entity API. I have created new entity named Projects. Goal is to make a project management system for software services providers. I am actually trying to figuring out the mechanism for workflow. I have a entity now. How would i let the user with role Manager add a new project and a user with role Developer can add updates to it like status, files attachment etc.

I need a basic overview so that i can use Drupal to build application rather than a content based website.

Thanks alot

6
  • well you would configure that through the permissons system and drupal will ha dle the rest...if you need field level permission (drupal handles entity/node access intrinsically) you would implement a module with required hooks or use an existing module like: Commented Nov 3, 2014 at 0:53
  • I know about permissions but how would i give the user interface for interacting with projects
    – user38296
    Commented Nov 3, 2014 at 1:04
  • if you see erpal system built on drupal. I want the very basic of that thing
    – user38296
    Commented Nov 3, 2014 at 1:04
  • You created an entity called project (machine name), what entity type is that? I assume, it is a node type. Then your user may (with permissions set) go to http://yourdomain.com/node/add/project to create new projects.
    – Paul
    Commented Nov 3, 2014 at 5:40
  • No, its not in node. Its a project entity type.
    – user38296
    Commented Nov 3, 2014 at 11:19

1 Answer 1

0

First off, we should define CRUD permissions for your entities in a correct manner. We will have to implement hook_permssion to define each of our crud permissions similar to the following:

function myentitymodule_permission() {
  return array(
    'view my entity' => array(
      'title' => t('View my custom entity'),
    ),
    'create my entity' => array(
      'title' => t('Create my custom entity'),
    ),
    'edit my entity' => array(
      'title' => t('Edit my custom entity'),
    ),
    'delete my entity' => array(
      'title' => t('Delete my custom entity'),
    ),
  );
}

The implementation of these newly created permissions should reside in your hook_menu implementation that is responsible for creating the CRUD pages you need.

function myentitymodule_menu() {
  $items = array();
  $items['my-entity/add'] = array(
    'title' => 'Add my new custom entity',
    'page callback' => 'myentitymodule_add_page',
    'access arguments' => array('create my entity'),
  );
  $items['my-entity/%entityid'] = array(
    'title callback' => 'myentitymodule_page_title',
    'title arguments' => array(1),
    'page callback' => 'myentitymodule_page_view',
    'page arguments' => array(1),
    'access arguments' => array('view my entity'),
  );
  $items['my-entity/%entityid/view'] = array(
    'title' => 'View',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['my-entity/%entityid/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'myentitymodule_page_edit',
    'page arguments' => array(1),
    'access arguments' => array('edit my entity'),
    'weight' => 0,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items['my-entity/%entityid/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('myentitymodule_delete_confirm'),
    'access arguments' => array('delete my entity'),
    'weight' => 1,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_INLINE,
  );

  return $items;
}

Notice the "access arguments" key of each new page defined in the above function need the array keys of your hook_permission implementation. Please note that you will have to create appropriate page callbacks that (should) reside in inc files in order to do things like render the entity view page and render the creation, edit and deletion pages. These callbacks should (at least) take the ID of the entity as an argument.

If we were to compare your custom entity to that of the node entity, the ID that is used for nodes is the nid. That's why pages like node/321/edit exist and use "321" as that ID argument. I think you want to accomplish more or less the same thing.

2
  • That is an amazing answer bro ! One last thing . Does the entity api provides methods for the crud. Do i have to manually build forms as a page callback for add, edit pages so and mannually insert the records in database on form submissions ? Or are there any defined methods in entity api. I understand that entity_create like functions are there to accomplish this thing but what about the forms ?
    – user38296
    Commented Nov 4, 2014 at 20:34
  • As far as I know, you have to manually create forms. Also it's a very bad practice to use db functions to interact with entity data as that bypasses any preprocessing that your entity controllers would take care of. Using helper functions from the entity api module (drupal.org/project/entity) like entity_save and entity_delete is the way to go. These are the functions you would use in your form submission callbacks. Commented Nov 5, 2014 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.