Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Forked from anonymous/after.php
Created November 3, 2013 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msonnabaum/7294177 to your computer and use it in GitHub Desktop.
Save msonnabaum/7294177 to your computer and use it in GitHub Desktop.
<?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')
);
}
}
<?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