You are here

function autofloat_simplytest_install in AutoFloat 7.2

Implements hook_install().

Perform actions to set up a Simplytest.me demo site for this module. We can count on all usual content types and text formats being available.

File

simplytest/autofloat_simplytest.install, line 13
Create a menu link and frontpage node.

Code

function autofloat_simplytest_install() {
  $t = get_t();

  // Create a link to the settings page in the main menu.
  $item = array(
    'link_title' => $t('AutoFloat settings'),
    'link_path' => 'admin/config/content/autofloat',
    'menu_name' => 'main-menu',
    'weight' => 1,
  );
  menu_link_save($item);

  // Add the AutoFloat filter to the Full HTML text format.
  $full_html_format = array(
    'format' => 'full_html',
    'name' => 'Full HTML',
    'weight' => 1,
    'filters' => array(
      // URL filter.
      'filter_url' => array(
        'weight' => 0,
        'status' => 1,
      ),
      // Line break filter.
      'filter_autop' => array(
        'weight' => 1,
        'status' => 1,
      ),
      // AutoFloat filter.
      'filter_autofloat' => array(
        'weight' => 3,
        'status' => 1,
      ),
      // HTML corrector filter.
      'filter_htmlcorrector' => array(
        'weight' => 10,
        'status' => 1,
      ),
    ),
  );
  $full_html_format = (object) $full_html_format;
  filter_format_save($full_html_format);

  // Make sure resized default images exist.
  $sample_image_medium = variable_get('image_style_preview_image', drupal_get_path('module', 'image') . '/sample.png');
  $styled_file = image_style_path('medium', $sample_image_medium);
  if (!file_exists($styled_file)) {
    image_style_create_derivative(image_style_load('medium'), $sample_image_medium, $styled_file);
  }
  $sample_image_medium = '/' . variable_get('file_public_path', conf_path() . '/files') . str_replace('public:/', '', $styled_file);
  $sample_image_thumb = variable_get('image_style_preview_image', drupal_get_path('module', 'image') . '/sample.png');
  $styled_file = image_style_path('thumbnail', $sample_image_thumb);
  if (!file_exists($styled_file)) {
    image_style_create_derivative(image_style_load('thumbnail'), $sample_image_thumb, $styled_file);
  }
  $sample_image_thumb = '/' . variable_get('file_public_path', conf_path() . '/files') . str_replace('public:/', '', $styled_file);

  // Create a sample page.
  $node = new stdClass();
  $node->uid = 1;
  $node->language = 'und';
  $node->type = 'page';
  $node->status = 1;
  $node->promote = 1;
  $node->title = $t('Demo of the AutoFloat module.');
  $node->body['und'][0]['value'] = $t('<p>Log in and check out the AutoFloat settings <strong><em><a href="/admin/config/content/autofloat">HERE</a></em></strong>. Re-save node to see settings changes.</p><div class="style-settings-preview"><h3>Justified.</h3><p style="text-align: justify;"><img src="' . $sample_image_medium . '" />Lectus purus ut urna! Et velit et vel sociis mid lundium habitasse, porttitor habitasse et, proin! Et vel porttitor, parturient sagittis lorem ac. Lorem! Nisi ultricies cum diam lundium turpis enim platea. Enim proin etiam platea non a diam integer platea scelerisque? Pulvinar et dis? Sit nunc purus, tortor montes egestas. Cras magna eu? Integer dignissim. Velit turpis pellentesque arcu integer cursus aenean quis natoque! Turpis sed dolor platea, tincidunt.</p><h3>Non-justified. Image within paragraph.</h3><p>Augue lectus magna? Porttitor amet pulvinar dapibus natoque pulvinar. Tristique nec, placerat elementum pulvinar amet. Tincidunt non velit diam, placerat mus, vut pid proin hac lacus lacus cursus penatibus nisi rhoncus! <img src="' . $sample_image_thumb . '" />Tristique amet natoque mattis augue velit tortor in, cum aliquam integer proin porta habitasse vel nisi, non non duis facilisis! Integer ultricies non magna eros lacus nisi etiam! Sagittis! Ac ut quis. Tristique. Lacus aliquam mus, pulvinar dignissim. Integer, habitasse urna cursus augue, odio enim mauris porta integer risus placerat dolor, et! In, integer nunc sociis ridiculus ac egestas. Purus pulvinar, sed pulvinar, integer purus! Phasellus, enim mauris montes, mauris montes massa pellentesque vut et ut dictumst turpis natoque cum cras cras? Nunc duis aliquam enim sit egestas elementum cursus? Nisi nisi tristique turpis. Mauris placerat pid, rhoncus, tristique, nisi, placerat penatibus adipiscing elementum, placerat rhoncus est ac. Scelerisque, eu! In mauris mauris ut turpis? Porttitor nec auctor! Magna elementum porttitor. Nunc ridiculus vel nunc augue natoque placerat phasellus dignissim, scelerisque turpis.</p></div><!--break-->');
  $node->body['und'][0]['format'] = 'full_html';
  node_save($node);

  // Create some admin quick links in the navigation menu.
  $item = array(
    'link_title' => $t('AutoFloat settings'),
    'link_path' => 'admin/config/content/autofloat',
  );
  menu_link_save($item);
}