-
-
Save msonnabaum/7294177 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ContentEntityFormController extends EntityFormController { | |
public function getFormLangcode(array &$form_state) { | |
if (empty($form_state['langcode'])) { | |
$form_state['langcode'] = $this->entityManager()->getTranslationFromContext($this->entity)->language()->id; | |
} | |
return $form_state['langcode']; | |
} | |
private function entityManager() { | |
if (!$this->entityManager) { | |
$this->entityManager = \Drupal::entityManager(); | |
} | |
$this->entityManager = $entity_manager; | |
} | |
/** | |
* Optional to simplify unit testing. | |
*/ | |
public function setEntityManager(EntityManagerInterface $entity_manager) { | |
$this->entityManager = $entity_manager; | |
} | |
} | |
class BookOutlineForm extends ContentEntityFormController { | |
public function __construct(BookManager $book_manager) { | |
$this->bookManager = $book_manager; | |
} | |
public static function create(ContainerInterface $container) { | |
return new static( | |
$container->get('book.manager') | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ContentEntityFormController extends EntityFormController { | |
public function __construct(EntityManagerInterface $entity_manager) { | |
$this->entityManager = $entity_manager; | |
} | |
public function getFormLangcode(array &$form_state) { | |
if (empty($form_state['langcode'])) { | |
$form_state['langcode'] = $this->entityManager->getTranslationFromContext($this->entity)->language()->id; | |
} | |
return $form_state['langcode']; | |
} | |
} | |
class BookOutlineForm extends ContentEntityFormController { | |
public function __construct(EntityManagerInterface $entity_manager, BookManager $book_manager) { | |
parent::__construct($entity_manager); | |
$this->bookManager = $book_manager; | |
} | |
public static function create(ContainerInterface $container) { | |
return new static( | |
$container->get('entity.manager'), | |
$container->get('book.manager') | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment