How to add a class to entityform inputs - drupal-7

I have an entityform block and I want to add bootstrap classes to its input!
How can I do this and what files should I edit?
I'm using latest version of entityform and entity block on drupal.org
thank you

You need to add these functions to your template.php file inside your theme folder (replace THEME_NAME with the actual name of your theme):
function THEME_NAME_textfield($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'text';
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
_form_set_class($element, array('form-text'));
$element['#attributes']['class'][] = 'form-control';
$extra = '';
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = "<div class='input-wrapper'>";
$output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
$output .= "</div>";
return $output . $extra;
}
function THEME_NAME_button($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'submit';
element_set_attributes($element, array('id', 'name', 'value'));
$element['#attributes']['class'][] = 'form-' . $element['#button_type'];
$element['#attributes']['class'][] = 'btn btn-default';
if (!empty($element['#attributes']['disabled'])) {
$element['#attributes']['class'][] = 'form-button-disabled';
}
$value = $element['#attributes']["value"];
if( isset($element['#attributes']["button-type"]) && $element['#attributes']["button-type"] == "search" ) {
$value = $element['#attributes']["icon"];
unset($element['#attributes']["icon"]);
}
return '<button' . drupal_attributes($element['#attributes']) . '>' . $value . '</button>';
}
function THEME_NAME_select($variables) {
$element = $variables['element'];
element_set_attributes($element, array('id', 'name', 'size'));
_form_set_class($element, array('form-select', 'form-control'));
return '<select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select>';
}
These functions will add the classes you need for the button, textfield and select input types. Also you will need to include the bootstrap files in your theme.

Related

Sitemap custom module

I am writing a custom module for site map in drupal 7. What I had done is below.
function escorts_sitemap_render_menu ($menu)
{
$output = "<ul>";
foreach ($menu as $item)
{
$link = $item["link"];
if ($link["hidden"])
{
continue;
}
$output .= "<li>" . $link["title"] . "</li>";
if ($item["below"])
{
$output .= sitemap_render_menu($item["below"]);
}
}
$output .= "</ul>";
return $output;
}
function escorts_sitemap_content ()
{
$output = "<h1>Escorts Sitemap</h1>";
$output .= "<ul class=\"site_map_list\">";
$output .= sitemap_render_menu(menu_tree_all_data("main-menu"));
return $output;
}
function escorts_sitemap_menu ()
{
$items = array();
$items["sitemap"] = array (
"title" => "Escorts Sitemap",
"page callback" => "escorts_sitemap_content",
"access arguments" => array("access content"),
"type" => MENU_CALLBACK);
return $items;
}
then in template.php I implemented hook_theme too, below is the code :
function escorts_theme() {
return array(
'escorts_sitemap_content' => array(
'render element' => 'content',
'template' => 'page--sitemap',
'path' => drupal_get_path('theme', 'escorts') . '/templates'
),
);
}
But it is not appearing as I have my custom template file page--sitemap.tpl.php, can any one please guide me. But now what should I write in page--sitemap.tpl.php in order to render my sitemap
Maybe You should try next:
function escorts_theme() {
return array(
'escorts_sitemap_content' => array(
'variables' => array('content' => NULL)
/**
* I would not call template like this, cause it looks like
* pattern page--[node-type]
*/
'template' => 'page--sitemap',
)
);
}
And inside of menu callback function
function escorts_sitemap_content () {
$output = "<h1>Escorts Sitemap</h1>";
$output .= "<ul class=\"site_map_list\">";
$output .= sitemap_render_menu(menu_tree_all_data("main-menu"));
return theme('escorts_sitemap_content', $output);
}
This is one of ways. Also look in preprocess functions, and Drupal theme layer at all. And maybe ready module XML sitemap will be useful. Also be careful, if file is really located there.
And in template file just paste
<?php print $content; ?>
Regards

Cakephp controller action does not redirect on live server

I have a action to save data in 4 models. Here is my controller code. I do get any error for saving data, I double checked it, But this action does not redirect to given url after it saves data, all it shows is a blank page of same action (action which is used to save data). This problem is only on live server. In my local copy is just working fine.
if ($this->request->is('post')) {
//First upload user pic
if ($this->request->data['FacilityResident']['pic']['name'] != NULL) {
$pic = $this->request->data['FacilityResident']['pic']['tmp_name'];
if (!is_dir(WWW_ROOT . 'img' . DS . 'residents' . DS)) {
mkdir(WWW_ROOT . 'img' . DS . 'residents' . DS);
chmod(WWW_ROOT . 'img' . DS . 'residents' . DS, 0777);
}
$uniq = mt_rand();
move_uploaded_file($pic, WWW_ROOT . 'img' . DS . 'residents' . DS . $this->request->data['FacilityResident']['pic']['name']);
$this->request->data['FacilityResident']['avatar'] = DS . 'residents' . DS . $this->request->data['FacilityResident']['pic']['name'];
unset($this->request->data['FacilityResident']['pic']);
}
$this->request->data['FacilityResident']['facilities_id'] = $this->Session->read('urlparam.facilityId');
$this->FacilityResident->save($this->request->data['FacilityResident']);
$residentId = $this->FacilityResident->getLastInsertID();
if (!empty($this->request->data['FacilityResidentDietary']['diet'])) {
$dietData = implode(',', $this->request->data['FacilityResidentDietary']['diet']);
unset($this->request->data['FacilityResidentDietary']['diet']);
$this->request->data['FacilityResidentDietary']['diet'] = $dietData;
}
$this->request->data['FacilityResidentDietary']['facility_residents_id'] = $residentId;
$this->FacilityResidentDietary->save($this->request->data['FacilityResidentDietary']);
$this->request->data['ResidentMealschedule']['facility_residents_id'] = $residentId;
$this->ResidentMealschedule->save($this->request->data['ResidentMealschedule']);
$residentMealSchedultId = $this->ResidentMealschedule->getLastInsertID();
foreach ($this->request->data['Mealdetail'] as $key => $value) {
if ($key == 'Bread') {
$value[0]['attribute_four'] = implode(',', array_filter($value[0]['attribute_four']));
}
foreach ($value as $val) {
$this->Mealdetail->saveAll($val);
$data['Mealschedule']['meal_types_id'] = 1;
$data['Mealschedule']['resident_mealschedule_id'] = $residentMealSchedultId;
$data['Mealschedule']['mealdetails_id'] = $this->Mealdetail->getLastInsertID();
$this->Mealschedule->saveAll($data);
}
unset($data);
unset($val);
}
$i = 1;
foreach ($this->request->data['ResidentMealMeta'] as $key => $val) {
$data['ResidentMealMeta'][$i]['resident_mealschedule_id'] = $residentMealSchedultId;
$data['ResidentMealMeta'][$i]['meal_value'] = $key;
$data['ResidentMealMeta'][$i]['meal_option'] = $val;
$i++;
}
if (!empty($this->request->data['ResidentTray']['tray'][0])) {
$j = count($data['ResidentMealMeta']) + 1;
$data['ResidentMealMeta'][$j]['meal_value'] = 'tray';
$data['ResidentMealMeta'][$j]['resident_mealschedule_id'] = $residentMealSchedultId;
$data['ResidentMealMeta'][$j]['meal_option'] = implode(',', $this->request->data['ResidentTray']['tray']);
}
unset($this->request->data['ResidentMealMeta']);
unset($this->request->data['ResidentTray']);
if ($this->ResidentMealMeta->saveAll($data['ResidentMealMeta'])) {
$this->Session->setFlash('New resident added', 'flash', array('alert' => 'success'));
if(isset($url)){
unset($url);
}
$url = Router::url(array(
'controller' => 'residents',
'action' => 'resident_list',
'?' => array('facility_name' => $this->Session->read('urlparam.facilityName'), 'facility_id' => $this->Session->read('urlparam.facilityId'))
));
$this->redirect($url);
}
}
can any one here tell me what is going wrong? I have also tried saving data via related model, but no effect.
I suggest to use this solution :
Router::redirect(
'/controller_where_you_re_saving_data/*',
array('controller' => 'residents', 'action' => 'resident_list'),
// view action expects $id as an argument
array('facility_name' => $this->Session->read('url.facilityName'))
);
However , i suggest to not pass the argument when it 's about sessions values , cause you can access to it in every controller in you project , which make the solution like this :
Router::redirect(
'/controller_where_you_re_saving_data/*',
array('controller' => 'residents', 'action' => 'resident_list'),
);
Here is the document :
http://book.cakephp.org/2.0/en/development/routing.html#redirect-routing
Hope it helps.

Drupal 7 render an array in Block_view

I want to render an array and print the output as Block[content]. There is either my Foreach or the way I use $item array or $row that is wrong. I will appreciate your help.
function produkt_block_view($delta = '')
{
$block = array();
$list = produkt_produkliste(1);
$items = array();
foreach ($list as $row) {
$items[1] = $row->uri;
$items[2] = $row->title;
$items[3] = $row->body_value;
}
switch($delta) {
case 'produkt' :
$block['content'] = '<a href="/19">';
$block['content'] .= '<img class="pimg" src="'.$row->uri.'" alt="Se alle vores filter elementer her">';
$block['content'] .= '<p class="pname">"'.$row->title.'"</p>';
$block['content'] .= '<p>"'.$row->body_value.'"</p>';
$block['content'] .= theme ('item_list',array('items' => $items, 'type' => 'ol', 'attribute' => 'produkt'));
break;
}
return $block;
}

wordpress custom post show some post in a div and rest posts in some different div

In wordpress I have made a custom post type. So for custom post type my code looks like this
add_action( 'init', 'broker_post_type' );
function broker_post_type() {
register_post_type( 'new_broker',
array(
'labels' => array(
'name' => __( 'Brands' ),
'singular_name' => __( 'Brand' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
)
);
}
To show the contents of custom posts through shortcode I have done like this
function display_broker_posts() {
$args = array(
'post_type' => 'new_broker',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
);
$dee_bios = new WP_Query( $args );
if( $dee_bios->have_posts() ):
$dee_output = '<div id="brokers-wrap">';
$dee_output .= '<div id="brokers-bg-wrap">';
$dee_output .= '<div class="brokers-content">';
$dee_output .= '<div class="brokers-left-content">';
while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
if( $dee_bios->current_post == 0 || ( $dee_bios->current_post % 2 ) == 0 ) {
$dee_output .= '<a class="branding first" href=""><div class="one-half first">';
}
else {
$dee_output .= '<a href="" class="branding"><div class="one-half">';
}
$dee_output .= get_the_post_thumbnail( $dee_bios->post->ID,'small', 'bios', array( 'class' => 'alignleft' ) );
$dee_output .= '<span></span>';
// $dee_output .= '<p><strong>' . get_the_title() . ',</strong> ' . get_the_content() . '</p>';
$dee_output .= '</div><!--end .one-half-->';
endwhile;
$dee_output .= '<div class="clear"></div><!--clear all floats-->';
$dee_output .= '</div><!-- end #bios-->';
endif;
wp_reset_postdata();
return $dee_output;
}
add_shortcode( 'display_brokers', 'display_broker_posts' );
Here its working fine. I can see the featured image in my page by using shortcode. But lets say I have 20 custom posts and I want that the first 6 will show in a different div and another 14 in another div. So can someone kindly tell me how to do this? Any help will be really appreciable. Thanks
How about something like this:
$dee_bios = new WP_Query( $args );
$i = 0;
if( $dee_bios->have_posts() ):
while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
if ($i ==0) {
$dee_output .= '<div id="first_broker_div">';
} elseif ($i == 6) {
$dee_output .= '</div><div id="second_broker_div">';
}
$dee_output .= //Your post content
$i++;
endwhile;
$dee_output .= '</div>';
endif;

Cakephp2.3 html->url in custom function

I am using Cakephp2.0 i created a custom function
<?php echo GenerateNavHTML($navarray); ?>
<?php
function GenerateNavHTML($nav)
{
if(!empty($nav)) {
if(isset($nav[0]['parent'])) {
$parentid=$nav[0]['parent'];
}else{
$parentid=1;
}
if($parentid==0) {
$html = '<ul style="display: block;" class="nav">';
}else {
$html='<ul>';
}
foreach($nav as $page) {
$html.='<li>';
$html .= '"'.$this->Html->url('Logout',array('controller'=>'users','action'=>'logout')).'"';
$html .= '</li>';
}
$html.='</ul>';
return $html;
}
}
?>
and it give
Fatal error: Cannot redeclare GenerateNavHTML()
But there is no redeclaration of function.
if i write
<?php
function GenerateNavHTML($nav)
{
if(!empty($nav)) {
if(isset($nav[0]['parent'])) {
$parentid=$nav[0]['parent'];
}else{
$parentid=1;
}
if($parentid==0) {
$html = '<ul style="display: block;" class="nav">';
}else {
$html='<ul>';
}
foreach($nav as $page) {
$html.='<li>';
$html .= '';
$html .= '</li>';
}
$html.='</ul>';
return $html;
}
}
?>
and it is working fine
i want to use cakephp syntax
Thanks
In MVC, this code should be part of a Helper, not just a standalone 'function'.
Creating your own Helper
This may sound hard, but it really isn't. It has many advantages as well; by moving your code to a Helper, it's easier to re-use and maintain.
For example;
Create a 'Navigation' helper (of course, give it a logical name);
app/View/Helper/NavigationHelper.php
class NavigationHelper extends AppHelper
{
/**
* Other helpers used by *this* helper
*
* #var array
*/
public $helpers = array(
'Html',
);
/**
* NOTE: In general, convention is to have
* functions/methods start with a lowercase
* only *Classes* should start with a capital
*
* #param array $nav
*
* #return string
*/
public function generateNavHTML($nav)
{
$html = '';
if (!empty($nav)) {
if (isset($nav[0]['parent'])) {
$parentid = $nav[0]['parent'];
} else {
$parentid = 1;
}
if ($parentid == 0) {
$html = '<ul style="display: block;" class="nav">';
} else {
$html = '<ul>';
}
foreach ($nav as $page) {
$html .= '<li>';
$html .= '"' . $this->Html->url('Logout', array('controller' => 'users', 'action' => 'logout')) . '"';
$html .= '</li>';
}
$html .= '</ul>';
}
// NOTE: moved this 'outside' of the 'if()'
// your function should always return something
return $html;
}
/**
* You can add other methods as well
* For example, a 'Convenience' method to create a link to the Homepage
*
* Simply use it like this:
* <code>
* echo $this->Navigation->logoutLink();
* </code>
*/
public function logoutLink()
{
return $this->Html->link(__('Log out'), array(
'controller' => 'users',
'action' => 'logout',
'confirm' => __('Are you sure you want to log out')
));
} }
Once you created that file, you can use it in any view or element;
echo $this->Navigation->generateNavHTML($navarray);
You don't even have to add it to the 'Helpers' array of your controller, because CakePHP 2.3 uses 'autoloading' to do that for you
If you need other functionality (related to 'Navigation'), you can just add a 'method' to the Helper, I added a 'logoutLink()' method just to illustrate this
For more information, read this chapter Creating Helpers
Try this:
<?php echo $this->GenerateNavHTML($navarray); ?>
And declare the function before all for secure

Resources