Introduce new getQuickId() and setQuickId() methods. Deprecate getId().

This commit is contained in:
Michael Stenta 2023-08-04 17:09:51 -04:00
parent 11c6e5be7e
commit 898d2355f0
7 changed files with 52 additions and 9 deletions

View File

@ -20,6 +20,13 @@ class QuickFormBase extends PluginBase implements QuickFormInterface, ContainerF
use MessengerTrait;
use StringTranslationTrait;
/**
* The quick form ID.
*
* @var string
*/
protected string $quickId;
/**
* Constructs a QuickFormBase object.
*
@ -49,18 +56,32 @@ class QuickFormBase extends PluginBase implements QuickFormInterface, ContainerF
);
}
/**
* {@inheritdoc}
*/
final public function setQuickId(string $id) {
return $this->quickId = $id;
}
/**
* {@inheritdoc}
*/
final public function getQuickId() {
return $this->quickId ?? $this->getPluginId();
}
/**
* {@inheritdoc}
*/
public function getId() {
return $this->getPluginId();
return $this->getQuickId();
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return $this->getId();
return $this->getQuickId();
}
/**

View File

@ -16,6 +16,27 @@ interface QuickFormInterface extends FormInterface {
* @return string
* The quick form ID.
*/
public function getQuickId();
/**
* Sets the quick form ID.
*
* @param string $id
* The quick form ID.
*/
public function setQuickId(string $id);
/**
* Returns the quick form ID.
*
* @return string
* The quick form ID.
*
* @deprecated in farm:2.2.0 and is removed from farm:3.0.0.
* Use QuickFormInterface::getQuickId() instead.
*
* @see https://www.drupal.org/node/3379686
*/
public function getId();
/**

View File

@ -81,6 +81,7 @@ class QuickFormInstanceManager implements QuickFormInstanceManagerInterface {
// First attempt to load a quick form instance config entity.
$entity = $this->entityTypeManager->getStorage('quick_form')->load($id);
if (!empty($entity)) {
$entity->getPlugin()->setQuickId($id);
return $entity;
}

View File

@ -27,7 +27,7 @@ trait ConfigurableQuickFormTrait {
* @return string
* The quick form ID.
*/
abstract public function getId();
abstract public function getQuickId();
/**
* {@inheritdoc}

View File

@ -25,7 +25,7 @@ trait QuickAssetTrait {
* @return string
* The quick form ID.
*/
abstract public function getId();
abstract public function getQuickId();
/**
* Create an asset.
@ -48,7 +48,7 @@ trait QuickAssetTrait {
$asset = Asset::create($values);
// Track which quick form created the entity.
$asset->quick[] = $this->getId();
$asset->quick[] = $this->getQuickId();
// Save the asset.
$asset->save();

View File

@ -26,7 +26,7 @@ trait QuickLogTrait {
* @return string
* The quick form ID.
*/
abstract public function getId();
abstract public function getQuickId();
/**
* Create a log.
@ -70,7 +70,7 @@ trait QuickLogTrait {
}
// Track which quick form created the entity.
$log->quick[] = $this->getId();
$log->quick[] = $this->getQuickId();
// Save the log.
$log->save();

View File

@ -20,7 +20,7 @@ trait QuickPrepopulateTrait {
* @return string
* The quick form ID.
*/
abstract public function getId();
abstract public function getQuickId();
/**
* Get prepopulated entities.
@ -61,7 +61,7 @@ trait QuickPrepopulateTrait {
// Load the temp store for the quick form.
/** @var \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory */
$temp_store_factory = \Drupal::service('tempstore.private');
$temp_store = $temp_store_factory->get('farm_quick.' . $this->getId());
$temp_store = $temp_store_factory->get('farm_quick.' . $this->getQuickId());
// Load entities from the temp store.
$temp_store_key = $user->id() . ':' . $entity_type;