View more context

 

MichalKleiner

we have a custom helper, something along these lines…

  1. /**
  2.   * Reorder tabs in the content section of the CMS, with the ability to change their titles
  3.   *
  4.   * @param FieldList $fields
  5.   * @param array $tabsOrder
  6.   * @param string $topTabName
  7.   * @return FieldList
  8.   */
  9. public static function reorderCmsTabs(FieldList &$fields, array $tabsOrder, string $topTabName = 'Root'): FieldList
  10. {
  11. foreach ($fields as $field) {
  12. if (($field instanceof TabSet) && ($field->getName() === $topTabName)) {
  13. $tabs = $field->Tabs();
  14.  
  15. foreach (array_reverse($tabsOrder) as $tabName => $tabTitle) {
  16. if (is_numeric($tabName)) {
  17. $tabName = $tabTitle;
  18. }
  19. /** @var Tab $tabToMove */
  20. if ($tabToMove = $tabs->fieldByName($tabName)) {
  21. $fields->removeByName($tabName);
  22. if (($tabTitle !== $tabName) && ($tabTitle !== $tabToMove->Title())) {
  23. $tabToMove->setTitle($tabTitle);
  24. }
  25. $tabs->unshift($tabToMove);
  26. }
  27. }
  28.  
  29. $field->setTabs($tabs);
  30. }
  31. }
  32.  
  33. return $fields;
  34. }
MichalKleiner

so it technically removes them and puts them back in a desired order

MichalKleiner

and you can pass it an array like ['Main', 'RelatedDocuments', 'RelatedPages' => 'Related articles', ]

sander_ha

If a module uses traits, is it even possible to use Injector to replace that Trait?

kinglozzer

Trait’s aren’t “constructed” like objects are, so Injector can’t touch them

wmk

you might of course subclass that class, overwrite that trait's method and use injector to use your custom version @sander_ha