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

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

    #1

    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
    EspoCRM product developer
    • Mar 2014
    • 10125

    #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

    • 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

      • bandtank
        Active Community Member
        • Mar 2017
        • 465

        #4
        I didn't see this topic before I created an issue in GitHub: https://github.com/espocrm/espocrm/issues/3885

        It seems like the behavior might never change, so workarounds are required. See the code linked in the issue for an example of how to do that.

        Comment

        Working...