Simplify the constructor of ViewDisplay.
parent
b93c8e0e54
commit
10db2c1799
|
@ -168,7 +168,7 @@ class ViewStorageTest extends WebTestBase {
|
||||||
$created_loaded = reset($loaded_entities);
|
$created_loaded = reset($loaded_entities);
|
||||||
$values_loaded = config('views.view.archive')->get();
|
$values_loaded = config('views.view.archive')->get();
|
||||||
|
|
||||||
$this->assertTrue(isset($created_loaded->display['default']->display_options), 'Make sure that the display options exists.');
|
$this->assertTrue(isset($created_loaded->display['default']->display_options), 'Make sure that the display options exist.');
|
||||||
$this->assertEqual($created_loaded->display['default']->display_plugin, 'default', 'Make sure the right display plugin is set.');
|
$this->assertEqual($created_loaded->display['default']->display_plugin, 'default', 'Make sure the right display plugin is set.');
|
||||||
|
|
||||||
$this->assertEqual($values, $values_loaded, 'The loaded config is the same as the original loaded one.');
|
$this->assertEqual($values, $values_loaded, 'The loaded config is the same as the original loaded one.');
|
||||||
|
|
|
@ -29,13 +29,19 @@ class ViewDisplay {
|
||||||
*/
|
*/
|
||||||
public $display_options;
|
public $display_options;
|
||||||
|
|
||||||
function __construct(array $display_options = array()) {
|
public function __construct(array $display_options = array()) {
|
||||||
if (!empty($display_options)) {
|
$display_options += array(
|
||||||
|
'display_options' => array(),
|
||||||
|
'display_plugin' => NULL,
|
||||||
|
'id' => NULL,
|
||||||
|
'display_title' => '',
|
||||||
|
'position' => NULL,
|
||||||
|
);
|
||||||
|
|
||||||
$this->display_options = $display_options['display_options'];
|
$this->display_options = $display_options['display_options'];
|
||||||
$this->display_plugin = $display_options['display_plugin'];
|
$this->display_plugin = $display_options['display_plugin'];
|
||||||
$this->id = $display_options['id'];
|
$this->id = $display_options['id'];
|
||||||
$this->display_title = $display_options['display_title'];
|
$this->display_title = $display_options['display_title'];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,6 @@ class ViewStorageController extends ConfigStorageController {
|
||||||
* Overrides Drupal\config\ConfigStorageController::create().
|
* Overrides Drupal\config\ConfigStorageController::create().
|
||||||
*/
|
*/
|
||||||
public function create(array $values) {
|
public function create(array $values) {
|
||||||
|
|
||||||
// If there is no information about displays available add at least the
|
// If there is no information about displays available add at least the
|
||||||
// default display.
|
// default display.
|
||||||
$values += array(
|
$values += array(
|
||||||
|
@ -124,13 +123,22 @@ class ViewStorageController extends ConfigStorageController {
|
||||||
*
|
*
|
||||||
* @param Drupal\entity\StorableInterface $entity
|
* @param Drupal\entity\StorableInterface $entity
|
||||||
*/
|
*/
|
||||||
protected function attachDisplays($entity) {
|
protected function attachDisplays(StorableInterface $entity) {
|
||||||
if (isset($entity->display) && is_array($entity->display)) {
|
if (isset($entity->display) && is_array($entity->display)) {
|
||||||
$displays = array();
|
$displays = array();
|
||||||
|
|
||||||
foreach ($entity->get('display') as $key => $options) {
|
foreach ($entity->get('display') as $key => $options) {
|
||||||
|
$options += array(
|
||||||
|
'display_options' => array(),
|
||||||
|
'display_plugin' => NULL,
|
||||||
|
'id' => NULL,
|
||||||
|
'display_title' => '',
|
||||||
|
'position' => NULL,
|
||||||
|
);
|
||||||
// Create a ViewDisplay object using the display options.
|
// Create a ViewDisplay object using the display options.
|
||||||
$displays[$key] = new ViewDisplay($options);
|
$displays[$key] = new ViewDisplay($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity->set('display', $displays);
|
$entity->set('display', $displays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue