You are here

function highcharttable_remove_page_from_decorations in HighchartTable 7

Removes the supplied page path from all decorations that use it.

If as a result of this the decoration no longer has any 'include-pages', then the decoration is removed altogether.

Parameters

string $page:

array $decorations:

1 call to highcharttable_remove_page_from_decorations()
highcharttable_contextual_link in ./highcharttable.module
Menu callback for highcharttable/contextual-link

File

./highcharttable.module, line 241
highcharttable.module

Code

function highcharttable_remove_page_from_decorations($page, &$decorations) {
  $url_options = array(
    'query' => array(
      'destination' => $page,
    ),
  );
  foreach ($decorations as $key => $decoration) {
    $include_pages = trim($decoration['pages-and-selector']['include-pages']);

    // Remove page path from 'include-pages', if found.
    $reduced = str_replace($page, '', $include_pages);
    if (strlen($reduced) < strlen($include_pages)) {
      $is_deleted = TRUE;
      if (empty($reduced)) {
        unset($decorations[$key]);
        drupal_set_message(t('Chart and chart decoration removed.'));
      }
      else {
        $decorations[$key]['pages-and-selector']['include-pages'] = $reduced;
        drupal_set_message(t('Chart removed. However, the underlying chart decoration was retained, as it appears to be used on other pages. Visit the <a href="@url_config">configuration page</a> to learn more.', array(
          '@url_config' => url('admin/config/content/highcharttable', $url_options),
        )));
      }
    }
  }
  if (empty($is_deleted)) {
    drupal_set_message(t('The chart was not removed. Most likely this was because this page is part of a wild-card specification shared with other charts. Visit the <a href="@url_config">configuration page</a> to learn more.', array(
      '@url_config' => url('admin/config/content/highcharttable', $url_options),
    )));
  }
}