flexy_mod-1.1.0/flexy_mod.module
flexy_mod.module
<?php
/**
* @file
* Contains flexy_mod.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
use Drupal\path_alias\Entity\PathAlias;
use Drupal\system\Entity\Menu;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Implements hook_preprocess_page()
*/
function flexy_mod_preprocess_page(&$variables) {
$variables['#attached']['library'][] = 'flexy_mod/slick';
}
/**
* Implements hook_help().
*/
function flexy_mod_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.flexy_mod':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Flexy mod is a dependent module for <a href="https://www.drupal.org/project/flexy_theme">Flexy theme.</a>') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dd><p>' . t('Once the module was installed, it will create a basic template for the website by creating content types, contents, custom blocks, view blocks, taxonomy etc. This will reduce the frontend developers time & they can customize their code by updating the layout & contents.') . '</p>';
$output .= '<a href="../../admin/structure/types/manage/flexy_mod" target="_blank">' . t('Flexy module') . '</a><br/>';
$output .= '</dl>';
return $output;
}
}
/**
* Implements hook_install().
*/
function flexy_mod_install() {
//Install vocobulary & terms
$vid = "category";
$categories = ['Drupal', 'UI/UX', 'Frontend', 'PHP'];
foreach ($categories as $category) {
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
'name' => $category,
'vid' => $vid,
])->save();
}
/*------- Creating content under about content type starts -------*/
// Create a file.
$file = File::create([
'uid' => 1,
'filename' => 'profile-default.png',
'uri' => drupal_get_path("module", "flexy_mod") . "/images/profile-default.png",
'status' => 1,
]);
// Save the file item.
$file->save();
// Ask for the current time.
$requested_time = \Drupal::time()->getRequestTime();
// Define basic values for the new node.
$node_about = Node::create([
'type' => 'about',
'langcode' => 'en',
'created' => $requested_time,
'changed' => $requested_time,
'uid' => 1,
'title' => 'About',
'body' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "<h2>COMPANY/PERSON NAME</h2><p>We are <span class='color'>HIGHLIGHTS. </span> Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>\r\n\r\n<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>",
'format' => 'full_html',
],
'field_main_description' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "<h2>Hi, Nice to See you!</h2><p><strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>\r\n\r\n<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p><p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>",
'format' => 'basic_html',
],
'field_image' => [
[
'target_id' => $file->id(),
'alt' => 'Profile image',
'title' => 'Profile image',
],
],
]);
// Save the node.
$node_about->save();
$path_alias = PathAlias::create([
'path' => '/node/' . $node_about->id(),
'alias' => '/about',
]);
$path_alias->save();
/*------- Creating content under about content type ends -------*/
/*------- Creating content under works content type starts -------*/
// Create a file.
$file_works = File::create([
'uid' => 2,
'filename' => 'default.png',
'uri' => drupal_get_path("module", "flexy_mod") . "/images/default.png",
'status' => 1,
]);
// Save the file item.
$file_works->save();
// Define basic values for the new node blog content type.
$node_blogs = Node::create([
'type' => 'blogs',
'langcode' => 'en',
'created' => $requested_time,
'changed' => $requested_time,
'uid' => 9,
'title' => 'Blog example',
'body' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "
<div class='content-wrp'>
<div class='content'>
<section>
<div class='header'>
<h2>Introduction</h2> </div>
<div class='body'>
<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<ul>
<li>Lorem Ipsum has been the industry's standard dummy text.</li>
<li>Lorem Ipsum has been the industry's standard dummy text</li>
</ul>
</div>
</section>
<section>
<div class='header'>
<h2>Overview</h2> </div>
<div class='body'>
<ul>
<li>Lorem Ipsum has been the industry's standard dummy text.</li>
<li>Lorem Ipsum has been the industry's standard dummy text</li>
<li>Lorem Ipsum has been the industry's standard dummy text.</li>
<li>Lorem Ipsum has been the industry's standard dummy text</li>
</ul>
</div>
</section>
</div>
</div>
",
'format' => 'full_html',
],
'field_image' => [
[
'target_id' => $file_works->id(),
'alt' => 'Blog image',
'title' => 'Blog image',
],
],
]);
// Save the node.
$node_blogs->save();
$path_alias = PathAlias::create([
'path' => '/node/' . $node_blogs->id(),
'alias' => '/blogs/blog-example',
]);
$path_alias->save();
// Define basic values for the new node.
$node_works = Node::create([
'type' => 'works',
'langcode' => 'en',
'created' => $requested_time,
'changed' => $requested_time,
'uid' => 2,
'title' => 'Example content one',
'body' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "<ul>
<li>Lorem Ipsum one</li>
<li>Lorem Ipsum two</li>
<li>Loreum Ipsum three</li>
</ul>",
'format' => 'full_html',
],
'field_project_description' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
'format' => 'basic_html',
],
'field_site_link' => [
'uri'=> 'https://example.com',
'title' => 'Test link'
],
'field_image' => [
[
'target_id' => $file_works->id(),
'alt' => 'Works image',
'title' => 'Works image',
],
],
]);
// Save the node.
$node_works->save();
$path_alias = PathAlias::create([
'path' => '/node/' . $node_works->id(),
'alias' => '/works/example-one',
]);
$path_alias->save();
// Define basic values for the new node.
$term_id = 35 ;
$node_works_two = Node::create([
'type' => 'works',
'langcode' => 'en',
'created' => $requested_time,
'changed' => $requested_time,
'uid' => 3,
'title' => 'Example content two',
'body' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "<ul>
<li>Lorem Ipsum one</li>
<li>Lorem Ipsum two</li>
<li>Loreum Ipsum three</li>
</ul>",
'format' => 'full_html',
],
'field_project_description' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
'format' => 'basic_html',
],
'field_site_link' => [
'uri'=> 'https://example.com',
'title' => 'Test link'
],
'field_category' => [
['target_id' => $term_id ]
],
'field_image' => [
[
'target_id' => $file_works->id(),
'alt' => 'Works image',
'title' => 'Works image',
],
],
]);
// Save the node.
$node_works_two->save();
$path_alias = PathAlias::create([
'path' => '/node/' . $node_works_two->id(),
'alias' => '/works/example-two',
]);
$path_alias->save();
// Define basic values for the new node.
$node_works_three = Node::create([
'type' => 'works',
'langcode' => 'en',
'created' => $requested_time,
'changed' => $requested_time,
'uid' => 4,
'title' => 'Example content three',
'body' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "<ul>
<li>Lorem Ipsum one</li>
<li>Lorem Ipsum two</li>
<li>Loreum Ipsum three</li>
</ul>",
'format' => 'full_html',
],
'field_project_description' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
'format' => 'basic_html',
],
'field_site_link' => [
'uri'=> 'https://example.com',
'title' => 'Test link'
],
'field_image' => [
[
'target_id' => $file_works->id(),
'alt' => 'Works image',
'title' => 'Works image',
],
],
]);
// Save the node.
$node_works_three->save();
$path_alias = PathAlias::create([
'path' => '/node/' . $node_works_three->id(),
'alias' => '/works/example-three',
]);
$path_alias->save();
// Define basic values for the new node.
$node_works_four = Node::create([
'type' => 'works',
'langcode' => 'en',
'created' => $requested_time,
'changed' => $requested_time,
'uid' => 5,
'title' => 'Example content four',
'body' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "<ul>
<li>Lorem Ipsum one</li>
<li>Lorem Ipsum two</li>
<li>Loreum Ipsum three</li>
</ul>",
'format' => 'full_html',
],
'field_project_description' => [
'summary' => 'Summary for the node created programmatically.',
'value' => "Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
'format' => 'basic_html',
],
'field_site_link' => [
'uri'=> 'https://example.com',
'title' => 'Test link'
],
'field_image' => [
[
'target_id' => $file_works->id(),
'alt' => 'Works image',
'title' => 'Works image',
],
],
]);
// Save the node.
$node_works_four->save();
$path_alias = PathAlias::create([
'path' => '/node/' . $node_works_four->id(),
'alias' => '/works/example-four',
]);
$path_alias->save();
/*------- Creating content under works content type ends -------*/
}
/**
* Implements hook_uninstall().
*/
function flexy_mod_uninstall() {
// Delete all nodes of created during module uninstall.
$storage_handler = \Drupal::entityTypeManager()
->getStorage('node');
$nodes_about = $storage_handler->loadByProperties(['type' => 'about']);
$nodes_works = $storage_handler->loadByProperties(['type' => 'works']);
$nodes_blogs = $storage_handler->loadByProperties(['type' => 'blogs']);
$storage_handler->delete($nodes_about);
$storage_handler->delete($nodes_works);
$storage_handler->delete($nodes_blogs);
}
