Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -10,16 +10,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
|||
|
||||
require_once dirname(__FILE__) . '/config_test.hooks.inc';
|
||||
|
||||
/**
|
||||
* Loads a ConfigTest object.
|
||||
*
|
||||
* @param string $id
|
||||
* The ID of the ConfigTest object to load.
|
||||
*/
|
||||
function config_test_load($id) {
|
||||
return entity_load('config_test', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_cache_flush().
|
||||
*/
|
||||
|
|
|
@ -8,13 +8,41 @@
|
|||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Form controller for the test config edit forms.
|
||||
*/
|
||||
class ConfigTestForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* The entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigTestForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
|
||||
* The entity query.
|
||||
*/
|
||||
public function __construct(QueryFactory $entity_query) {
|
||||
$this->entityQuery = $entity_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -33,7 +61,7 @@ class ConfigTestForm extends EntityForm {
|
|||
'#default_value' => $entity->id(),
|
||||
'#required' => TRUE,
|
||||
'#machine_name' => array(
|
||||
'exists' => 'config_test_load',
|
||||
'exists' => [$this, 'exists'],
|
||||
'replace_pattern' => '[^a-z0-9_.]+',
|
||||
),
|
||||
);
|
||||
|
@ -142,4 +170,25 @@ class ConfigTestForm extends EntityForm {
|
|||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the entity already exists.
|
||||
*
|
||||
* @param string|int $entity_id
|
||||
* The entity ID.
|
||||
* @param array $element
|
||||
* The form element.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the entity exists, FALSE otherwise.
|
||||
*/
|
||||
public function exists($entity_id, array $element, FormStateInterface $form_state) {
|
||||
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
|
||||
$entity = $form_state->getFormObject()->getEntity();
|
||||
return (bool) $this->entityQuery->get($entity->getEntityTypeId())
|
||||
->condition($entity->getEntityType()->getKey('id'), $entity_id)
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue