Possible bug in application/Espo/Tools/Layout/LayoutProvider

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BattleMetalChris
    Member
    • Mar 2021
    • 50

    Possible bug in application/Espo/Tools/Layout/LayoutProvider

    We found that in the get() function in LayoutProvider it was returning the default behaviour before it was checking the modules for overrrides.

    Just changing around a few lines so it checks the modules before the default has fixed it.

    Old function:

    Code:
    public function get(string $scope, string $name): ?string
    {
      if (
        $this->sanitizeInput($scope) !== $scope ||
        $this->sanitizeInput($name) !== $name
      ) {
        throw new RuntimeException("Bad parameters.");
      }
    
      $path = 'layouts/' . $scope . '/' . $name . '.json';
    
      $params = FileReaderParams::create()->withScope($scope);
    
      $module = $this->getLayoutLocationModule($scope, $name);
      if ($module) {
        $params = $params
          ->withScope(null)
          ->withModuleName($module);
      }
      if ($this->fileReader->exists($path, $params)) {
        return $this->fileReader->read($path, $params);
      }
      $default = $this->getDefault($scope, $name);
      if ($default) {
        return $default;
      }
      foreach (array_reverse($this->metadata->getModuleList()) as $module) {
        $params = FileReaderParams::create()->withModuleName($module);
    
        if ($this->fileReader->exists($path, $params)) {
          return $this->fileReader->read($path, $params);
        }
      }
    
      return null;
    }​
    New function

    Code:
    public function get(string $scope, string $name): ?string
    {
      if (
        $this->sanitizeInput($scope) !== $scope ||
        $this->sanitizeInput($name) !== $name
      ) {
        throw new RuntimeException("Bad parameters.");
      }
    
      $path = 'layouts/' . $scope . '/' . $name . '.json';
    
      $params = FileReaderParams::create()->withScope($scope);
    
      $module = $this->getLayoutLocationModule($scope, $name);
      if ($module) {
        $params = $params
          ->withScope(null)
          ->withModuleName($module);
      }
      if ($this->fileReader->exists($path, $params)) {
        return $this->fileReader->read($path, $params);
      }
    
      foreach (array_reverse($this->metadata->getModuleList()) as $module) {
        $params = FileReaderParams::create()->withModuleName($module);
    
        if ($this->fileReader->exists($path, $params)) {
          return $this->fileReader->read($path, $params);
        }
      }
      $default = $this->getDefault($scope, $name);
      if ($default) {
        return $default;
      }
      return null;
    }
  • yuri
    Member
    • Mar 2014
    • 8453

    #2
    It was deliberately added this way. No any compatibility backward break. Just adds the ability to add non-standard layouts.

    EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • Alanhick3
      Junior Member
      • Oct 2024
      • 1

      #3
      Hi Yuri,

      But isn't it more useful to check for the custom layout in the module BEFORE returning the default?

      Thanks

      Comment

      Working...