diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php index 7b2017b..12c96ac 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\shortcut\Plugin\Core\Entity\Shortcut. + * Contains \Drupal\shortcut\Entity\Shortcut. */ namespace Drupal\shortcut\Entity; @@ -10,7 +10,6 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Field\FieldDefinition; -use Drupal\Core\Routing\UrlMatcher; use Drupal\shortcut\ShortcutInterface; /** @@ -19,7 +18,6 @@ * @EntityType( * id = "shortcut", * label = @Translation("Shortcut link"), - * module = "shortcut", * controllers = { * "storage" = "Drupal\Core\Entity\FieldableDatabaseStorageController", * "access" = "Drupal\shortcut\ShortcutAccessController", diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php index c9dee35..a742d92 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php @@ -9,11 +9,10 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageControllerInterface; -use Drupal\shortcut\ShortcutInterface; use Drupal\shortcut\ShortcutSetInterface; /** - * Defines the Shortcut configuration entity. + * Defines the Shortcut set configuration entity. * * @EntityType( * id = "shortcut_set", diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php index 12a789c..8b03a2c 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php @@ -17,30 +17,11 @@ class SetCustomize extends EntityFormController { /** - * The shortcut storage controller. + * The entity being used by this form. * - * @var \Drupal\Core\Entity\EntityStorageControllerInterface + * @var \Drupal\shortcut\ShortcutSetInterface */ - protected $storageController; - - /** - * Constructs a SetCustomize object. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - */ - public function __construct(EntityManagerInterface $entity_manager) { - $this->storageController = $entity_manager->getStorageController('shortcut'); - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager') - ); - } + protected $entity; /** * {@inheritdoc} @@ -66,8 +47,7 @@ public function form(array $form, array &$form_state) { ), ); - $shortcuts = $this->storageController->loadByProperties(array('shortcut_set' => $this->entity->id())); - foreach ($shortcuts as $shortcut) { + foreach ($this->entity->getShortcuts() as $shortcut) { $id = $shortcut->id(); $form['shortcuts']['links'][$id]['#attributes']['class'][] = 'draggable'; $form['shortcuts']['links'][$id]['name']['#markup'] = l($shortcut->title->value, $shortcut->path->value); @@ -119,8 +99,7 @@ protected function actions(array $form, array &$form_state) { * {@inheritdoc} */ public function save(array $form, array &$form_state) { - $shortcuts = $this->storageController->loadByProperties(array('shortcut_set' => $this->entity->id())); - foreach ($shortcuts as $shortcut) { + foreach ($this->entity->getShortcuts() as $shortcut) { $shortcut->weight->value = $form_state['values']['shortcuts']['links'][$shortcut->id()]['weight']; $shortcut->save(); } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php index 5f72679..fc27fb9 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php @@ -8,13 +8,7 @@ namespace Drupal\shortcut; use Drupal\Core\Entity\ContentEntityFormController; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\Query\QueryFactory; -use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Language\Language; -use Drupal\Core\Path\AliasManagerInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the shortcut entity forms. @@ -22,68 +16,22 @@ class ShortcutFormController extends ContentEntityFormController { /** - * The path alias manager. + * The entity being used by this form. * - * @var \Drupal\Core\Path\AliasManagerInterface + * @var \Drupal\shortcut\ShortcutInterface */ - protected $aliasManager; - - /** - * The URL generator. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * The form builder. - * - * @var \Drupal\Core\Form\FormBuilderInterface - */ - protected $formBuilder; - - /** - * Constructs a new action form. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager - * The path alias manager. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The URL generator. - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. - */ - public function __construct(EntityManagerInterface $entity_manager, AliasManagerInterface $alias_manager, UrlGeneratorInterface $url_generator, FormBuilderInterface $form_builder) { - $this->entityManager = $entity_manager; - $this->aliasManager = $alias_manager; - $this->urlGenerator = $url_generator; - $this->formBuilder = $form_builder; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager'), - $container->get('path.alias_manager'), - $container->get('url_generator'), - $container->get('form_builder') - ); - } + protected $entity; /** * {@inheritdoc} */ public function form(array $form, array &$form_state) { $form = parent::form($form, $form_state); - $entity = $this->entity; $form['title'] = array( '#type' => 'textfield', '#title' => t('Name'), - '#default_value' => $entity->title->value, + '#default_value' => $this->entity->getTitle(), '#size' => 40, '#maxlength' => 255, '#required' => TRUE, @@ -95,28 +43,28 @@ public function form(array $form, array &$form_state) { '#title' => t('Path'), '#size' => 40, '#maxlength' => 255, - '#field_prefix' => $this->urlGenerator->generateFromRoute('', array(), array('absolute' => TRUE)), - '#default_value' => $entity->path->value, + '#field_prefix' => $this->url('', array(), array('absolute' => TRUE)), + '#default_value' => $this->entity->path->value, ); $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->id, + '#default_value' => $this->entity->getUntranslated()->language()->id, '#languages' => Language::STATE_ALL, ); $form['shortcut_set'] = array( '#type' => 'value', - '#value' => $entity->bundle(), + '#value' => $this->entity->bundle(), ); $form['route_name'] = array( '#type' => 'value', - '#value' => $entity->getRouteName(), + '#value' => $this->entity->getRouteName(), ); $form['route_parameters'] = array( '#type' => 'value', - '#value' => $entity->getRouteParams(), + '#value' => $this->entity->getRouteParams(), ); return $form; @@ -140,7 +88,7 @@ public function buildEntity(array $form, array &$form_state) { */ public function validate(array $form, array &$form_state) { if (!shortcut_valid_link($form_state['values']['path'])) { - $this->formBuilder->setErrorByName('path', $form_state, $this->t('The shortcut must correspond to a valid path on the site.')); + $this->setFormError('path', $form_state, $this->t('The shortcut must correspond to a valid path on the site.')); } parent::validate($form, $form_state); diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php index 7c44cba..9a6bb98 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutInterface.php @@ -44,7 +44,7 @@ public function getWeight(); /** * Sets the weight among shortcuts with the same depth. * - *·@param int $weight + * @param int $weight * The shortcut weight. * * @return \Drupal\shortcut\ShortcutInterface diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetInterface.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetInterface.php index 4289f78..21cc4f3 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetInterface.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetInterface.php @@ -10,7 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; /** - * Provides an interface defining a shortcut entity. + * Provides an interface defining a shortcut set entity. */ interface ShortcutSetInterface extends ConfigEntityInterface {