View source
<?php
use Drupal\gridbuilder\Grid;
const GRIDBUILDER_FIXED = 0;
const GRIDBUILDER_FLUID = 1;
function gridbuilder_menu() {
$items = array();
$items['admin/structure/grids'] = array(
'title' => 'Grids',
'description' => 'Manage list of grids which can be used with layouts.',
'page callback' => 'gridbuilder_page_list',
'access callback' => 'user_access',
'access arguments' => array(
'administer gridbuilder',
),
'file' => 'gridbuilder.admin.inc',
);
$items['admin/structure/grids/add'] = array(
'title' => 'Add grid',
'page callback' => 'gridbuilder_page_add',
'access callback' => 'user_access',
'access arguments' => array(
'administer gridbuilder',
),
'type' => MENU_LOCAL_ACTION,
'file' => 'gridbuilder.admin.inc',
);
$items['admin/structure/grids/grid/%gridbuilder/edit'] = array(
'title' => 'Edit grid',
'page callback' => 'gridbuilder_page_edit',
'page arguments' => array(
4,
),
'access callback' => 'user_access',
'access arguments' => array(
'administer gridbuilder',
),
'type' => MENU_CALLBACK,
'file' => 'gridbuilder.admin.inc',
);
$items['admin/structure/grids/grid/%gridbuilder/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gridbuilder_delete_confirm',
4,
),
'access callback' => 'user_access',
'access arguments' => array(
'administer gridbuilder',
),
'type' => MENU_CALLBACK,
'file' => 'gridbuilder.admin.inc',
);
return $items;
}
function gridbuilder_permission() {
return array(
'administer gridbuilder' => array(
'title' => t('Administer grid builder grids'),
'description' => t('Administer grids created with the grid builder.'),
),
);
}
function gridbuilder_entity_info() {
$types['grid'] = array(
'label' => 'Grid',
'entity class' => 'Drupal\\gridbuilder\\Grid',
'controller class' => 'Drupal\\Core\\Config\\Entity\\ConfigStorageController',
'form controller class' => array(
'default' => 'Drupal\\gridbuilder\\GridFormController',
),
'list controller class' => 'Drupal\\Core\\Config\\Entity\\ConfigEntityListController',
'list path' => 'admin/structure/grids',
'uri callback' => 'gridbuilder_uri',
'config prefix' => 'grid',
'entity keys' => array(
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
),
);
return $types;
}
function gridbuilder_uri(Grid $grid) {
return array(
'path' => 'admin/structure/grids/grid/' . $grid
->id(),
);
}
function gridbuilder_load($id) {
return entity_load('grid', $id);
}
function gridbuilder_load_all() {
return entity_load_multiple('grid');
}
function gridbuilder_get_css($name, $wrapper_selector = NULL, $span_selector_prefix = NULL, $skip_spacing = FALSE) {
$css = module_invoke_all('gridbuilder_get_css', $name);
if (!empty($css)) {
return join('', $css);
}
$grid = gridbuilder_load($name);
$css = '';
if (empty($wrapper_selector)) {
$wrapper_selector = '.rld-container-' . $grid
->id();
}
if (empty($span_selector_prefix)) {
$span_selector_prefix = '.rld-span_';
}
if ($skip_spacing) {
$grid->gutter_width = $grid->padding_width = 0;
}
switch ($grid->type) {
case GRIDBUILDER_FLUID:
$size_suffix = '%';
$grid->width = '100';
break;
case GRIDBUILDER_FIXED:
$size_suffix = 'px';
break;
}
$colwidth = ($grid->width - ($grid->columns - 1) * $grid->gutter_width) / $grid->columns;
$css = $wrapper_selector . ' .rld-col {
border: 0px solid rgba(0,0,0,0);
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-moz-background-clip: padding-box !important;
-webkit-background-clip: padding-box !important;
background-clip: padding-box !important;
margin-left: ' . $grid->gutter_width . $size_suffix . ';
padding: 0 ' . $grid->padding_width . $size_suffix . ';
}
' . $wrapper_selector . ' .rld-col' . $span_selector_prefix . 'first {
margin-left: 0;
clear: both;
}
';
for ($i = 1; $i <= $grid->columns; $i++) {
$css .= $wrapper_selector . ' ' . $span_selector_prefix . $i . " {\n";
if ($i == 1) {
$css .= ' width: ' . $colwidth * $i . $size_suffix . ";\n";
}
elseif ($i == $grid->columns) {
$css .= " width: " . $grid->width . $size_suffix . ";\n margin-left: 0;\n";
}
else {
$css .= ' width: ' . ($colwidth * $i + $grid->gutter_width * ($i - 1)) . $size_suffix . ";\n";
}
$css .= "}\n";
}
return $css;
}
function gridbuilder_manager() {
return drupal_container()
->get('plugin.manager.gridbuilder');
}