Skip to content
Snippets Groups Projects
Commit 91d2fd6f authored by AKHIL BABU's avatar AKHIL BABU Committed by Ted Bowman
Browse files

Issue #3522977 by akhil babu, meghasharma, mayur-sose: XB UI shows the *saved*...

Issue #3522977 by akhil babu, meghasharma, mayur-sose: XB UI shows the *saved* content entity's current title, not the auto-saved one
parent 32c3a3fd
No related branches found
No related tags found
1 merge request!993Load page title from auto saved data by default
Pipeline #492608 passed with warnings
......@@ -422,6 +422,15 @@ final class ApiLayoutController {
* @return string
*/
public function getLabel(EntityInterface $entity): string {
// Get title from auto saved data if available.
$autoSaveData = $this->autoSaveManager->getAutoSaveData($entity);
if (!$autoSaveData->isEmpty()) {
$data = $autoSaveData->data;
$label_field_input_name = sprintf("%s[0][value]", $entity->getEntityType()->getKey('label'));
if (isset($data['entity_form_fields'][$label_field_input_name])) {
return $data['entity_form_fields'][$label_field_input_name];
}
}
return (string) $entity->label();
}
......
......@@ -13,7 +13,6 @@ use Drupal\experience_builder\Plugin\DisplayVariant\XbPageVariant;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\Tests\experience_builder\Kernel\Traits\RequestTrait;
use Drupal\Tests\experience_builder\TestSite\XBTestSetup;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
......@@ -27,7 +26,6 @@ use Symfony\Component\HttpFoundation\Response;
*/
class ApiLayoutControllerGetTest extends ApiLayoutControllerTestBase {
use RequestTrait;
use UserCreationTrait;
/**
......@@ -124,6 +122,7 @@ class ApiLayoutControllerGetTest extends ApiLayoutControllerTestBase {
// Draft of highlighted region in global template should be returned even if
// there is no auto-save data for the node.
$response = $this->request(Request::create($url->toString()));
$this->assertTitle($node1->label() . ' | Drupal');
self::assertInstanceOf(JsonResponse::class, $response);
$json = \json_decode($response->getContent() ?: '', TRUE);
self::assertArrayHasKey('layout', $json);
......@@ -157,6 +156,7 @@ class ApiLayoutControllerGetTest extends ApiLayoutControllerTestBase {
\assert($node1 instanceof NodeInterface);
$autoSave->save($node1, $data);
$response = $this->request(Request::create($url->toString()));
$this->assertTitle("$new_title | Drupal");
self::assertInstanceOf(JsonResponse::class, $response);
$json = \json_decode($response->getContent() ?: '', TRUE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment