SocialNodeForm.php in Open Social 10.0.x
File
modules/social_features/social_node/src/SocialNodeForm.php
View source
<?php
namespace Drupal\social_node;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\node\NodeForm;
use Drupal\social_node\Service\SocialNodeMessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SocialNodeForm extends NodeForm {
public function __construct(EntityRepositoryInterface $entity_repository, PrivateTempStoreFactory $temp_store_factory, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, AccountInterface $current_user, DateFormatterInterface $date_formatter, SocialNodeMessengerInterface $messenger) {
parent::__construct($entity_repository, $temp_store_factory, $entity_type_bundle_info, $time, $current_user, $date_formatter);
$this
->setMessenger($messenger);
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('tempstore.private'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'), $container
->get('current_user'), $container
->get('date.formatter'), $container
->get('social_node.messenger'));
}
public function save(array $form, FormStateInterface $form_state) {
$node = clone $this->entity;
$this
->messenger()
->setNode($node);
parent::save($form, $form_state);
}
public function messenger() {
if (!isset($this->messenger)) {
$this->messenger = \Drupal::service('social_node.messenger');
}
return $this->messenger;
}
}