Drupal 8 es un entorno nuevo, un nuevo paradigma de programación dentro de Drupal. Charla sobre programación de módulos en D8, impartida en el DrupalSummer de Barcelona 2016.
Drupal 8 is a new environment, a new develop paradigm. This session is about drupal 8 module development, imparted in DrupalSummer 2016, in Barcelona.
27. Forms
public function validateForm(array &$form,
FormStateInterface $form_state) {
$values = $form_state->getValues();
if(!Drupal::service('email.validator')-
>isValid($values['mail'])) {
$form_state->setErrorByName('mail', $this-
>t('The email address %mail is not valid.',
array('%mail' => $values['mail'])));
}
}
example_dyb_landing/src/Form/ContactForm.php
28. Forms
public function submitForm(array &$form, FormStateInterface
$form_state) {
$values = $form_state->getValues();
$to = Drupal::config('system.site')->get('mail');
$language_interface = Drupal::languageManager()-
>getCurrentLanguage();
Drupal::service('plugin.manager.mail')-
>mail('example_dyb_landing', 'contact_message', $to,
$language_interface, $values, 'no-replyđ@mail.com');
drupal_set_message($this->t('Thank for contact us. Your
message has been sent correctly.'));
}
example_dyb_landing/src/Form/ContactForm.php
37. namespace Drupalregister_formForm;
use Drupalrest_clientRestClient;
class RegisterForm extends FormBase{
protected $client;
public function __construct(RestClient $client) {
$this->client = $client;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('rest_client.client'),
);
}
example_dyb_landing/src/Form/RegisterForm.php
Dependency injection
40. Mi primer theme
name: public
type: theme
description: Public theme.
package: Other
core: 8.x
libraries:
- public/global-styling
base theme: classy
regions:
content: Content
header: Header
footer: Footer
public/public.info.yml