|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acquia\DFExtension\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
|
6
|
|
|
use Drupal\Core\Entity\Entity\EntityViewMode; |
|
7
|
|
|
use Drupal\Core\Entity\EntityViewModeInterface; |
|
8
|
|
|
use Drupal\DrupalExtension\Context\DrupalSubContextBase; |
|
9
|
|
|
use Webmozart\Assert\Assert; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A context for working with entity display modes. |
|
13
|
|
|
*/ |
|
14
|
|
|
class DisplayModeContext extends DrupalSubContextBase { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Sets the customization status of a view mode. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $entity_type |
|
20
|
|
|
* The ID of the affected entity type. |
|
21
|
|
|
* @param string $bundle |
|
22
|
|
|
* (optional) The ID of the affected bundle. If omitted, the entity type is |
|
23
|
|
|
* presumed to not support bundles. |
|
24
|
|
|
* @param string $view_mode |
|
25
|
|
|
* (optional) The view mode ID. Defaults to 'default'. |
|
26
|
|
|
* @param bool $desired_status |
|
27
|
|
|
* (optional) Whether to customize or uncustomize the view mode. |
|
28
|
|
|
* |
|
29
|
|
|
* @When I customize :entity_type display |
|
30
|
|
|
* @When I customize the :view_mode :entity_type display |
|
31
|
|
|
* @When I customize the display of the :bundle :entity_type type |
|
32
|
|
|
* @When I customize the :view_mode display of the :bundle :entity_type type |
|
33
|
|
|
*/ |
|
34
|
|
|
public function setViewModeCustomization($entity_type, $bundle = NULL, $view_mode = 'default', $desired_status = TRUE) { |
|
35
|
|
|
$display = entity_get_display($entity_type, $bundle, $view_mode); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
if ($display->isNew()) { |
|
38
|
|
|
$display = entity_get_display($entity_type, $bundle, 'default') |
|
|
|
|
|
|
39
|
|
|
->createDuplicate() |
|
40
|
|
|
->set('mode', $view_mode); |
|
41
|
|
|
|
|
42
|
|
|
// If the display was created anew, its previous status is effectively |
|
43
|
|
|
// FALSE. |
|
44
|
|
|
$original_status = FALSE; |
|
45
|
|
|
} |
|
46
|
|
|
else { |
|
47
|
|
|
$original_status = $display->status(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** @var UndoContext $undo */ |
|
51
|
|
|
$undo = $this->getContext(UndoContext::class); |
|
52
|
|
|
if ($undo && $desired_status != $original_status) { |
|
53
|
|
|
$arguments = array_slice(func_get_args(), 0, 3); |
|
54
|
|
|
$arguments[] = $original_status; |
|
55
|
|
|
$undo->push([$this, __FUNCTION__], $arguments); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$display->setStatus($desired_status)->save(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Sets a description on an entity view mode. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $id |
|
65
|
|
|
* The view mode ID. |
|
66
|
|
|
* @param \Behat\Gherkin\Node\PyStringNode $description |
|
67
|
|
|
* The view mode description. |
|
68
|
|
|
* |
|
69
|
|
|
* @When I describe the :id view mode: |
|
70
|
|
|
*/ |
|
71
|
|
|
public function describeViewMode($id, PyStringNode $description) { |
|
72
|
|
|
$view_mode = EntityViewMode::load($id); |
|
73
|
|
|
|
|
74
|
|
|
Assert::isInstanceOf($view_mode, EntityViewModeInterface::class); |
|
75
|
|
|
|
|
76
|
|
|
/** @var UndoContext $undo */ |
|
77
|
|
|
$undo = $this->getContext(UndoContext::class); |
|
78
|
|
|
if ($undo) { |
|
79
|
|
|
$original_description = $view_mode |
|
80
|
|
|
->getThirdPartySetting('df_core', 'description'); |
|
81
|
|
|
|
|
82
|
|
|
$original = new PyStringNode([$original_description], 0); |
|
83
|
|
|
$undo->push([$this, __FUNCTION__], [$id, $original]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$view_mode |
|
87
|
|
|
->setThirdPartySetting('df_core', 'description', (string) $description) |
|
88
|
|
|
->save(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.