You are here

function media_browser_plus_get_media_root_folder in Media Browser Plus 7.3

Same name and namespace in other branches
  1. 7 media_browser_plus.module \media_browser_plus_get_media_root_folder()
  2. 7.2 media_browser_plus.module \media_browser_plus_get_media_root_folder()

Loads and (if $autocreate is set) creates the default media folder object.

Parameters

bool $autocreate: Creates the folder if necessary.

Return value

object|FALSE The folder term or FALSE if not found. During installation this can return FALSE!

15 calls to media_browser_plus_get_media_root_folder()
MediaBrowserPlusBypassTest::testBypassDueProperty in tests/media_browser_plus.mbp_bypass.test
Test the ability to bypass folder processing setting mbp_bypass property.
MediaBrowserPlusTest::testFileMovement in tests/media_browser_plus.test
Test the ability to delete folders.
MediaBrowserPlusTest::testInvalidFolderCreation in tests/media_browser_plus.test
Test if invalid structures are automatically fixed.
MediaBrowserPlusTestBase::createTestFile in tests/media_browser_plus.base.test
Creates a test file.
MediaBrowserPlusTestBase::folderCreationHelper in tests/media_browser_plus.base.test
Helper to create a folder structure based on an given array.

... See full list

File

./media_browser_plus.module, line 354
Media Browser Plus - enhanced file management functions.

Code

function media_browser_plus_get_media_root_folder($autocreate = FALSE) {
  $root_folder = FALSE;
  $vocabulary = taxonomy_vocabulary_machine_name_load('media_folders');
  if (!$vocabulary) {
    $t = get_t();
    $vocabulary = (object) array(
      'name' => 'Media Folders',
      'description' => $t('Use media folders to organize your media'),
      'machine_name' => 'media_folders',
      'hierarchy' => 1,
      'help' => $t('Enter a concise name for the media folder'),
    );
    taxonomy_vocabulary_save($vocabulary);
  }
  if ($vocabulary) {
    $root_folder = taxonomy_term_load(variable_get('media_browser_plus_root_folder_tid'));
    if ($root_folder === FALSE) {
      if ($autocreate) {
        $root_folder = new stdClass();
        $root_folder->name = 'Media Root';
        $root_folder->description = 'default media folder';
        $root_folder->vid = $vocabulary->vid;
        $root_folder->weight = '-10';
        $root_folder->parent = 0;
        $root_folder->autocreate = TRUE;
        taxonomy_term_save($root_folder);
        variable_set('media_browser_plus_root_folder_tid', $root_folder->tid);
      }
      elseif (!drupal_installation_attempted()) {
        watchdog('media_browser_plus', 'Unable to load the media root folder term. Please check the folder management!', array(), WATCHDOG_ERROR, 'admin/structure/taxonomy/' . $vocabulary->machine_name);
      }
    }
  }
  return $root_folder;
}