Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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;
    }

  • #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.

    Comment


    • #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...
      X