Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

routes - Custom aspect for routing not working as expected

I have coded a custom aspect which should just pass back, what it gets. This is working partly:

Working

?tx_myvender_users[action]=list&tx_myvender_users[company]=Company 1&tx_myvender_users[controller]=FrontendUser&tx_myvender_users[department]=SelectedDepartment&cHash=5413de3c7ca7efda6da4e9bb3a918945

Translates to

company-1/department/SelectedDepartment/

Not working with pagination

?tx_myvender_users[%40widget_0][currentPage]=2&tx_myvender_users[action]=list&tx_myvender_users[company]=Company 1&tx_myvender_users[controller]=FrontendUser&tx_myvender_users[department]=SelectedDepartment&cHash=e8196678ef65f1c4d5423b617505f840

Translates to

company-1/department/SelectedDepartment/2/

but it passes SelectedDepartment/2/ for the argument department and I don't get why. I would expect SelectedDepartment for department and 2 for the argument @widget_0/currentPage.

Here is my routes configuration in config.yaml:

routes: {  }
routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: /
    index: ''
    map:
      /: 0
  FeusersPlugin:
    type: Extbase
    extension: MyVendor
    plugin: Users
    limitToPages: [3]
    defaultController: 'FrontendUser::list'
    requirements:
      company_page: 'd+'
    routes:
      - routePath: '{company_title}/department/{department_title}'
        _controller: 'FrontendUser::list'
        _arguments:
          company_title: 'company'
          department_title: 'department'
      - routePath: '{company_title}/department/{department_title}/{company_page}'
        _controller: 'FrontendUser::list'
        _arguments:
          company_title: 'company'
          department_title: 'department'
          company_page: '@widget_0/currentPage'
    aspects:
      company_title:
        type: StaticValueMapper
        map:
          company-1: 'Company 1'
          company-2: 'Company 2'
      department_title:
        type: DepartmentStaticMapper
      company_page:
        type: StaticRangeMapper
        start: '1'
        end: '100'

And this is my DepartmentStaticMapper which is passing back what it gets:

namespace MyVendorExtensionRoutingAspect;

use TYPO3CMSCoreRoutingAspectStaticMappableAspectInterface;


class DepartmentStaticMapper implements StaticMappableAspectInterface
{
    protected $settings;

    public function __construct(array $settings)
    {
        $this->settings = $settings;
    }

    public function generate(string $value): ?string
    {
        return $value;
    }

    public function resolve(string $value): ?string
    {
        return $value;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Changing the class DepartmentStaticMapper to the following, solved my problem. I have just added a check for a slash in public function resolve(string $value):

namespace MyVendorExtensionRoutingAspect;

use TYPO3CMSCoreRoutingAspectStaticMappableAspectInterface;


class DepartmentStaticMapper implements StaticMappableAspectInterface
{
    protected $settings;

    public function __construct(array $settings)
    {
        $this->settings = $settings;
    }

    public function generate(string $value): ?string
    {
        return $value;
    }

    public function resolve(string $value): ?string
    {
        return strstr($value, '/') ? null : $value;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...