Comments

devin carlson’s picture

Status: Active » Needs review
StatusFileSize
new13.46 KB

Taking a stab at this.

Changes:

  • Removed (unused?) default.png image which is only referenced by media_variable_default().
  • Removed media_variable_name() and incorporated the media variable namespace directly into the administration
  • form form elements
  • Removed unused constants
  • Fixed doc block formatting
  • Changed static to &drupal_static
  • Removed unused variable defaults
  • Removed deprecated variables
  • Fixed media_variable_default() to return NULL when the default value of a variable has not been set (per the existing documentation)

Moved the modified code to media.module.

Status: Needs review » Needs work

The last submitted patch, cleanup-media-variables-1406948-1.patch, failed testing.

devin carlson’s picture

Status: Needs work » Needs review
StatusFileSize
new13.72 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, cleanup-media-variables-1406948-3.patch, failed testing.

devin carlson’s picture

Status: Needs work » Needs review
StatusFileSize
new13.71 KB

And once more.

dave reid’s picture

I also want to get rid of media_variable_set() and media_variable_del() as those only do namespacing. For the default variables and media_variable_get() let's do the following:

 media.module:

/**
 * Internal default variables for media_variable_get().
 */
function media_variables() {
  return array(
    'media__wysiwyg_title' => t('Media browser'),
    'media__wysiwyg_icon_title' => t('Add media'),
    'media__wysiwyg_default_view_mode' => 'media_large',
    ...
  );
}

/**
 * Wrapper for variable_get() with automatic media namespacing and defaults.
 *
 * @param string $name
 *   The name of the media variable to return. Should not include the 'media__'
 *   prefix.
 * @param mixed $default_override
 *   (optional) The default value to pass along to variable_get(). If not
 *   provided, the default from media_variables() will be used if available.
 *   Otherwise, NULL will be used as the default.
 *
 * @return mixed
 *    The value of the variable from variable_get().
 */
function media_variable_get($name, $default_override = NULL) {
  $defaults = &drupal_static(__FUNCTION__);
  if (!isset($defaults)) {
    $defaults = media_variables();
  }

  // Add the media variable namespace.
  $name = 'media__' . $name;

  // Use the default variable from media_variables() if desired and it exists.
  $default = !isset($default_override) && isset($defaults[$name]) ? $defaults['name'] : $default_override;

  // Return the variable.
  return variable_get($name, $default);
}
ParisLiakos’s picture

Status: Needs review » Needs work
jerdavis’s picture

Following up on this as the current state of Media (in official and dev releases as of today) results in errors when attempting to run database updates. In particular, media_update_7206() fails as it is trying to call media_variable_get() and failing. Either these changes need to be pushed through or a module_load_include('inc', 'media', 'includes/media.variables'); needs to be added to this update for it to complete.

ParisLiakos’s picture

@#18 http://drupalcode.org/project/media.git/commit/e2c3a74 and http://drupalcode.org/project/media.git/commit/ed0cc08 should take care of that.
i think we should consider integrating with variable module..right now media.variables.inc, just does what variable module would for free..

dave reid’s picture

Assigned: dave reid » Unassigned
Issue tags: +7.x-2.0 beta blocker

Let's put this as a beta blocker. I do not want to add a dependency on the variable module. If it is worth doing optional integration, I would consider that, but I just want us to use normal variable_get() calls.

ParisLiakos’s picture

normal variable_get() calls is fine. i proposed variable module as the media.variables.inc replacement..removing it entirely without replacement is fine too :)

devin carlson’s picture

Assigned: Unassigned » devin carlson
Status: Needs work » Needs review
StatusFileSize
new21.84 KB

A patch to convert every occurrence of media_variable_* to variable_*.

Once this is in, I'll file a followup to remove the double underscore from the variable names.

devin carlson’s picture

Status: Needs review » Fixed

Retested #13 and didn't run into any problems.

Committed to Media 7.x-2.x.

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