Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Provide an Admin UI for Your Entity

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:06
    In this lesson, we're going to take a look at the code
  • 0:08
    that's required in order to provide an administrative UI for our entity.
  • 0:13
    We've now got the ability to store entities in the database,
  • 0:18
    but it would be great if we can make it so that someone could add an entity
  • 0:21
    by just filling out a form and clicking the save button.
  • 0:24
    The entity API provides us with a lot of it for free but not everything.
  • 0:29
    So, we're going to take a look at the pieces that we get for free
  • 0:33
    just by adding our UI controller,
  • 0:35
    and then we're going to take a look at what we need to do
  • 0:38
    in order to fill in the rest of the gaps like creating a form

Provide an Admin UI for Your Entity


Update your hook_entity_info implementation to take advantage of the Admin UI provided by the Entity API and quickly provide users of your site access to all the Entity CRUD operations via the UI. The API gives us a really good head start but we still need to write some code in order to provide a useable form for administrators. The API doesn’t make any assumptions about things like validating input so we also need to take care of that ourselves.

This video adds a new permission that allows privileged users administer our new videoasset entities. If you're following along as a user other than user 1 you'll need to make sure you give yourself the proper permissions. In the video, I'm logged in as the user with the ID of 1 so I'm just granted the permissions automatically.

Note: If you're following along with the videos in sequence there's an error that needs correcting. At the end of the previous video code was added to videoentity_entity_info() that references a VideoEntityUIController class, however, the definition of that class was not added. Which, will cause a PHP error because the class is missing.

In order to correct this error, you'll want to add the following code to the bottom of your videoentity.module file. This just ensures that the class is defined so that there are no errors. If you're curious about what it does it's explained in the last part of the previous video.

* Our custom controller for the admin ui.
class VideoEntityUIController extends EntityDefaultUIController {}

In a later tutorial in this series, we'll customize the form for our video entity by adding more code to this class.

Note: At 14:10 on line 36 this line is added:

'#value' => isset($VideoAsset->id) ? t('Update video asset') : t('Save video

It should be:

'#value' => isset($video->id) ? t('Update video asset') : t('Save video

Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.