You are here

function responsive_preview_get_devices_list in Responsive Theme Preview 7

Returns a list of devices and their properties from configuration.

2 calls to responsive_preview_get_devices_list()
responsive_preview_block_view in ./responsive_preview.module
Implements hook_block_view().
responsive_preview_navbar in ./responsive_preview.module
Implements hook_navbar().

File

./responsive_preview.module, line 87
Provides a component that previews the a page in various device dimensions.

Code

function responsive_preview_get_devices_list() {
  $devices = array();
  try {
    $devices = db_select('responsive_preview', 'rp')
      ->fields('rp')
      ->condition('status', 1)
      ->orderBy('weight', 'ASC')
      ->execute()
      ->fetchAllAssoc('name', PDO::FETCH_ASSOC);
  } catch (Exception $e) {
    watchdog_exception('responsive_preview', $e);
    throw $e;
  }
  $links = array();
  foreach ($devices as $name => $info) {
    $item = array(
      '#theme' => 'html_tag',
      '#tag' => 'button',
      '#value' => $info['label'],
      '#attributes' => array(
        'class' => array(
          'responsive-preview-device',
          'responsive-preview-icon',
          'responsive-preview-icon-active',
        ),
        'data-responsive-preview-name' => $name,
        'data-responsive-preview-width' => !empty($info['width']) ? $info['width'] : '',
        'data-responsive-preview-height' => !empty($info['height']) ? $info['height'] : '',
        'data-responsive-preview-dppx' => !empty($info['dppx']) ? $info['dppx'] : '1',
      ),
    );
    $links[$name] = array(
      // theme_item_list() doesn't work in D7 like it does in D8. You have to render items before
      // passing them in.
      'data' => drupal_render($item),
    );
  }

  // Add a configuration link.
  $configlink = array(
    '#theme' => 'link',
    '#text' => t('Configure devices'),
    '#path' => 'admin/config/content/responsive-preview',
    '#options' => array(
      'attributes' => array(
        'class' => array(
          'responsive-preview-configure',
        ),
      ),
      'html' => FALSE,
    ),
  );
  $links['configure_link'] = array(
    'data' => drupal_render($configlink),
  );
  return $links;
}