diff --git a/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceFormController.php b/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceFormController.php index 4ef993b..2ba1a08 100644 --- a/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceFormController.php +++ b/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceFormController.php @@ -27,7 +27,6 @@ public function form(array $form, array &$form_state, EntityInterface $responsiv '#size' => 30, '#required' => TRUE, '#maxlength' => 64, - '#description' => t('The name for this device. Example: "Small", "Medium", "HTC One", "Google Glass", "Smart TV".'), ); $form['id'] = array( '#type' => 'machine_name', @@ -42,8 +41,7 @@ public function form(array $form, array &$form_state, EntityInterface $responsiv ); $dimensions = $entity->get('dimensions'); $form['dimensions'] = array( - '#type' => 'details', - '#title' => t('Dimensions'), + '#type' => 'container', '#tree' => TRUE, ); $form['dimensions']['width'] = array( @@ -65,6 +63,7 @@ public function form(array $form, array &$form_state, EntityInterface $responsiv $form['dimensions']['dppx'] = array( '#type' => 'textfield', '#title' => t('Dots per pixel (dppx)'), + '#description' => t('Size of a single dot in graphical representation. Classic desktop displays have 1dppx, typical modern smartphones and laptops have 2dppx or higher. For example Google Nexus 4 and iPhone 5 has 2dppx, while Google Nexus 7 has 1.325dppx and Samsung Galaxy S4 has 3dppx.'), '#default_value' => $dimensions['dppx'], '#size' => 4, '#required' => TRUE, @@ -76,9 +75,8 @@ public function form(array $form, array &$form_state, EntityInterface $responsiv '#options' => array('portrait' => t('Portrait'), 'landscape' => t('Landscape')), ); $form['status'] = array( - '#type' => 'checkbox', - '#title' => t('Show in preview list'), - '#default_value' => $entity->get('status'), + '#type' => 'value', + '#value' => $entity->get('status'), ); $form['weight'] = array( '#type' => 'value', diff --git a/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceListController.php b/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceListController.php index ab76894..5da4bac 100644 --- a/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceListController.php +++ b/core/modules/responsive_preview/lib/Drupal/responsive_preview/DeviceListController.php @@ -30,9 +30,8 @@ public function buildHeader() { $row = parent::buildHeader(); unset($row['operations']); $row['label'] = t('Name'); - $row['dimensions'] = t('Dimensions'); - $row['orientation'] = t('Default orientation'); $row['status'] = t('Show in list'); + $row['dimensions'] = t('Dimensions'); unset($row['id']); $row['weight'] = t('Weight'); $row['operations'] = t('Operations'); @@ -52,18 +51,18 @@ public function buildRow(EntityInterface $entity) { unset($row['id']); $row['label'] = array( - '#markup' => check_plain($row['label']), + '#markup' => check_plain($entity->label()), + ); + $row['status'] = array( + '#type' => 'checkbox', + '#title' => t('Show %title in list', array('%title' => $entity->label())), + '#title_display' => 'invisible', + '#default_value' => $entity->get('status'), ); $dimensions = $entity->get('dimensions'); $row['dimensions'] = array( '#markup' => check_plain($dimensions['width'] . 'x' . $dimensions['height'] . ' (' . $dimensions['dppx'] . ' dppx)'), ); - $row['orientation'] = array( - '#markup' => $entity->get('orientation') == 'landscape' ? t('Landscape') : t('Portrait'), - ); - $row['status'] = array( - '#markup' => $entity->get('status') ? t('yes') : t('no'), - ); $row['#weight'] = $entity->get('weight'); // Add weight column. $row['weight'] = array( @@ -104,7 +103,7 @@ public function buildForm(array $form, array &$form_state) { $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Save order'), + '#value' => t('Save'), '#button_type' => 'primary', ); @@ -126,9 +125,10 @@ public function submitForm(array &$form, array &$form_state) { $entities = entity_load_multiple($this->entityType, array_keys($values)); foreach ($values as $id => $value) { - if (isset($entities[$id]) && $value['weight'] != $entities[$id]->get('weight')) { + if (isset($entities[$id]) && (($value['weight'] != $entities[$id]->get('weight')) || ($value['status'] != $entities[$id]->get('status')))) { // Update changed weight. $entities[$id]->set('weight', $value['weight']); + $entities[$id]->set('status', $value['status']); $entities[$id]->save(); } } diff --git a/core/modules/responsive_preview/lib/Drupal/responsive_preview/Tests/DeviceCRUDTest.php b/core/modules/responsive_preview/lib/Drupal/responsive_preview/Tests/DeviceCRUDTest.php index d789b2d..ce89a12 100644 --- a/core/modules/responsive_preview/lib/Drupal/responsive_preview/Tests/DeviceCRUDTest.php +++ b/core/modules/responsive_preview/lib/Drupal/responsive_preview/Tests/DeviceCRUDTest.php @@ -46,17 +46,17 @@ function testDeviceConfiguration() { $this->assertLinkByHref('admin/config/content/responsive-preview/manage/large/delete'); $this->assertLinkByHref('admin/config/content/responsive-preview/manage/ipad/delete'); - // Generic devices are shown by default. + // Some devices are shown by default. $this->drupalGet(''); - $this->checkDevices(array('medium', 'small')); + $this->checkDevices(array('iphone5', 'ipad', 'nexus4', 'nexus7')); - // Delete one of the predefined generic items. - $this->drupalPost('admin/config/content/responsive-preview/manage/medium/delete', array(), t('Delete')); - $this->assertRaw(t('Device %name has been deleted.', array('%name' => 'Tablet'))); + // Delete one of the predefined devices. + $this->drupalPost('admin/config/content/responsive-preview/manage/iphone5/delete', array(), t('Delete')); + $this->assertRaw(t('Device %name has been deleted.', array('%name' => 'iPhone 5'))); - // Make iPad appear in the list. - $this->drupalPost('admin/config/content/responsive-preview/manage/ipad', array('status' => 1), t('Save')); - $this->assertRaw(t('Device %name has been updated.', array('%name' => 'iPad'))); + // Make generic tablet appear in the list. + $this->drupalPost('admin/config/content/responsive-preview', array('entities[medium][status]' => 1), t('Save')); + $this->assertRaw(t('The device settings have been updated.')); // Add a new device as well. $edit = array( @@ -65,14 +65,13 @@ function testDeviceConfiguration() { 'dimensions[width]' => '200', 'dimensions[height]' => '350', 'dimensions[dppx]' => '3', - 'status' => 1, ); $this->drupalPost('admin/config/content/responsive-preview/add', $edit, t('Save')); $this->assertRaw(t('Device %name has been added.', array('%name' => 'Smartwatch'))); - // Check updated device list applied. + // Check updated device list. New devices are shown in the list by default. $this->drupalGet(''); - $this->checkDevices(array('smartwatch', 'ipad', 'small')); + $this->checkDevices(array('smartwatch', 'ipad', 'medium', 'nexus4', 'nexus7')); } /**