Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We need to clean-up our current implementation of the media browser plugins:
- Let's stop using the CTools plugin system. It gives us no real benefits. What we really wanted is versioning, which is completely separate from the plugin system. We can implement our own media_get_browser_plugins() which checks ctools_plugin_api_info() and invokes hook_media_browser_plugin() and caches it itself. This will also help clean up hook_media_browser_plugin since we only need to specify a 'class' rather than the more complex data that CTools needs when all we need are autoloaded classes.
- Properly abstract the MediaBrowserPlugin class into an interface (for documentation) and an abstract class. End result will look something like this: http://palantir.privatepaste.com/affdde6e9c This will have a benefit of throwing an automatic error if a plugin class doesn't implement the view() function.
- Move the access callback into an 'access' method in the plugin.
- Add a MediaBrowserMenuCallbackPlugin class that easily allows a menu router path to be used as a browser tab plugin (or a MenuBrowserFormPlugin). This could assist #1398896: Decouple Add media page from media browser as our plugins for upload and web could easily be menu router paths of file/add/upload and file/add/url.
Before:
$plugins['upload'] = array(
'title' => t('Upload'),
'weight' => -10,
'handler' => array(
'path' => drupal_get_path('module', 'media') . '/includes',
'file' => 'MediaBrowserUpload.inc',
'class' => 'MediaBrowserUpload',
),
'access callback' => 'media_access',
'access arguments' => array('edit'),
);
After:
$plugins['upload'] = array(
'title' => t('Upload'),
'weight' => -10,
'class' => 'MediaBrowserUpload',
);
Comment | File | Size | Author |
---|---|---|---|
#8 | 1400200-media-browser-plugin-cleanup-part3.patch | 10.89 KB | Dave Reid |
#6 | 1400200-media-browser-plugin-cleanup-part2.patch | 11.83 KB | Dave Reid |
#2 | 1400200-media-browser-plugin-cleanup.patch | 9.5 KB | Dave Reid |
Comments
Comment #1
Dave ReidComment #2
Dave ReidFirst phase: implement the first part: stop using CTools plugin system.
Comment #3
Dave ReidPatch in #2 has been committed to Git.
http://drupalcode.org/project/media.git/commit/8670623
Comment #4
DamienMcKennaI think that means it's fixed? :)
Comment #5
Dave ReidNo, I still have to address parts 2-4 of the original issue now. :)
Comment #6
Dave ReidPart 2, defining a proper interface and an abstract class.
Comment #7
Dave ReidTested #6 to pushed to Git: http://drupalcode.org/project/media.git/commit/3665957
Comment #8
Dave ReidHere's part three which implements MediaBrowserPluginInterface::access() on all the tabs. Also helps cleanup the Views tab code by re-using $this->view.
Comment #9
Dave ReidCommitted phase three with http://drupalcode.org/project/media.git/commit/0c3e982. I'm going to consider this fixed for now. I'll make a separate issue for the MediaBrowserMenuPath plugin.