Exemplo n.º 1
0
 /**
  * @ticket 50977
  *
  * @dataProvider providerGetType
  */
 public function testGetTypeFunction($module, $type)
 {
     $SM = new StudioModule($module);
     $this->assertEquals($type, $SM->getType(), 'Failed asserting that module:' . $module . ' is of type:' . $type);
 }
 /**
  * Gets the metadata from various non module locations as a fallback. If 
  * no metadata file is found, will log an error and return an empty set of 
  * viewdefs.
  * 
  * @param string $marker The property to set when metadata is found
  * @return array
  */
 public function getFallbackMetadata($marker = 'loadedMetadataFile')
 {
     // Prepare the return
     $viewdefs = array();
     // Get our module type
     $sm = new StudioModule($this->_moduleName);
     $template = $sm->getType();
     // Build an array of files to search defs for
     $files = array();
     if (!$this->_viewClient !== 'base') {
         // This is the OOTB file for this module in the base client
         $files[] = $this->getMetadataFilename(MB_BASEMETADATALOCATION, null, 'base');
     }
     // This is the metadata file for this module type
     $files[] = $this->getMetadataFilename('', $template, 'base');
     if ($template !== 'basic') {
         // This is the metadata file for basic modules
         $files[] = $this->getMetadataFilename('', 'basic', 'base');
     }
     // Used for logging
     $found = false;
     // Loop and set
     foreach ($files as $file) {
         if (file_exists($file)) {
             require $file;
             if (!empty($viewdefs)) {
                 // This needs to be done in the event we have a SugarObject template file in use
                 $viewdefs = MetaDataFiles::getModuleMetaDataDefsWithReplacements($this->bean, $viewdefs);
                 if (isset($viewdefs[$this->_moduleName])) {
                     $this->{$marker} = $file;
                     $found = true;
                     break;
                 }
             }
         }
     }
     // If we found nothing, log it
     if (!$found) {
         $GLOBALS['log']->error("Could not find a filter file for {$this->_moduleName}");
     }
     return $viewdefs;
 }
 /**
  * Sets up the class vars for the file information
  * @return bool
  * @throws Exception
  */
 protected function setupSubpanelViewDefFileInfo()
 {
     $client = $this->getViewClient();
     $this->sidecarSubpanelName = $this->getSidecarSubpanelViewName($this->loadedModule, $this->linkName);
     if ($client !== 'base') {
         $layoutFiles[] = "modules/{$this->loadedModule}/clients/base/layouts/subpanels/subpanels.php";
     }
     // check if there is an override
     $layoutFiles = array("modules/{$this->loadedModule}/clients/{$client}/layouts/subpanels/subpanels.php");
     foreach ($layoutFiles as $file) {
         @(include $file);
     }
     $extension = "custom/modules/{$this->loadedModule}/Ext/clients/{$client}/layouts/subpanels/subpanels.ext.php";
     if (SugarAutoLoader::fileExists($extension)) {
         @(include $extension);
     }
     $overrideSubpanelName = null;
     $overrideSubpanelFileName = null;
     if (!empty($viewdefs[$this->loadedModule][$client]['layout']['subpanels']['components'])) {
         $components = $viewdefs[$this->loadedModule][$client]['layout']['subpanels']['components'];
         foreach ($components as $key => $component) {
             if (empty($component['override_subpanel_list_view'])) {
                 continue;
             }
             if (is_array($component['override_subpanel_list_view']) && $component['override_subpanel_list_view']['link'] == $this->linkName) {
                 $this->loadedSubpanelName = $component['override_subpanel_list_view']['view'];
                 $path = "modules/{$this->_moduleName}/clients/{$client}" . "/views/{$this->loadedSubpanelName}/{$this->loadedSubpanelName}.php";
                 $this->loadedSubpanelFileName = file_exists("custom/{$path}") ? "custom/{$path}" : $path;
                 $this->sidecarFile = "custom/modules/{$this->_moduleName}/clients/{$client}" . "/views/{$this->sidecarSubpanelName}/{$this->sidecarSubpanelName}.php";
                 $this->overrideArrayKey = $key;
                 return true;
             }
             // handle revenuelineitems' subpanel-for-opportunities
             if (!empty($component['context']['link']) && $component['context']['link'] == $this->linkName) {
                 $overrideSubpanelName = $component['override_subpanel_list_view'];
                 $overrideSubpanelFileName = "modules/{$this->_moduleName}/clients/{$client}" . "/views/{$overrideSubpanelName}/{$overrideSubpanelName}.php";
                 break;
             }
         }
     }
     $subpanelFile = "modules/{$this->_moduleName}/clients/{$client}" . "/views/{$this->sidecarSubpanelName}/{$this->sidecarSubpanelName}.php";
     $defaultSubpanelFile = "modules/{$this->_moduleName}/clients/base/views/subpanel-list/subpanel-list.php";
     $this->loadedSubpanelName = $this->sidecarSubpanelName;
     $studioModule = new StudioModule($this->_moduleName);
     $defaultTemplate = $studioModule->getType();
     $defaultTemplateSubpanelFile = "include/SugarObjects/templates/{$defaultTemplate}/clients/base/views/subpanel-list/subpanel-list.php";
     $baseTemplateSubpanelFile = "include/SugarObjects/templates/basic/clients/base/views/subpanel-list/subpanel-list.php";
     // using includes because require_once causes an empty array
     if (file_exists('custom/' . $subpanelFile)) {
         $this->loadedSubpanelFileName = 'custom/' . $subpanelFile;
     } elseif (file_exists($subpanelFile)) {
         $this->loadedSubpanelFileName = $subpanelFile;
     } elseif (!empty($overrideSubpanelName) && file_exists($overrideSubpanelFileName)) {
         $this->loadedSubpanelFileName = $overrideSubpanelFileName;
         $this->loadedSubpanelName = $overrideSubpanelName;
     } elseif (file_exists($defaultSubpanelFile)) {
         $this->loadedSubpanelFileName = $defaultSubpanelFile;
         $this->loadedSubpanelName = 'subpanel-list';
     } elseif (file_exists($defaultTemplateSubpanelFile)) {
         $this->loadedSubpanelFileName = $defaultTemplateSubpanelFile;
         $this->loadedSubpanelName = 'subpanel-list';
     } elseif (file_exists($baseTemplateSubpanelFile)) {
         $this->loadedSubpanelFileName = $baseTemplateSubpanelFile;
         $this->loadedSubpanelName = 'subpanel-list';
     } else {
         throw new Exception("No metadata file found for subpanel: {$this->loadedSubpanelName}");
     }
     $this->sidecarFile = "custom/" . $subpanelFile;
 }