View source
<?php
namespace Drupal\social_core\Form;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class InviteEmailBaseForm extends FormBase {
protected $routeMatch;
protected $entityTypeManager;
protected $loggerFactory;
protected $group;
public function __construct(RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager, LoggerChannelFactoryInterface $logger_factory) {
$this->routeMatch = $route_match;
$this->entityTypeManager = $entity_type_manager;
$this->loggerFactory = $logger_factory;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('current_route_match'), $container
->get('entity_type.manager'), $container
->get('logger.factory'));
}
public function getFormId() {
return 'invite_email_base_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['users_fieldset'] = [
'#type' => 'fieldset',
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#attributes' => [
'class' => [
'form-horizontal',
],
],
];
$form['users_fieldset']['user'] = [
'#title' => $this
->t('Find people by name or email address'),
'#type' => 'select2',
'#description' => $this
->t('You can enter or paste multiple entries separated by comma or semicolon'),
'#multiple' => TRUE,
'#tags' => TRUE,
'#autocomplete' => TRUE,
'#selection_handler' => 'social',
'#target_type' => 'user',
'#select2' => [
'tags' => TRUE,
'placeholder' => t('Jane Doe, johndoe@example.com'),
'tokenSeparators' => [
',',
';',
],
'autocomplete' => FALSE,
],
'#required' => TRUE,
'#validated' => TRUE,
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Send your invite(s) by email'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
public function extractEmailsFrom($string) {
$string = str_replace('$ID:', '', $string);
preg_match_all("/[\\._a-zA-Z0-9+-]+@[\\._a-zA-Z0-9+-]+/i", $string, $matches);
return $matches[0];
}
}