I'm using Views Basic UI in Drupal 6 to allow users to edit a views header and title. I would like to cut back on the number of view templates that I have, so that in the future if I need to edit, I would only have to make changes in one place.
To do that, I'd like the views template "views-view--page.tpl.php" to provide a link only if the view is editable as defined by the Views Basic UI: Edit Settings module. I'm just not sure what the code should look like. I think it'd be something along the lines of
<?php if (in_array('views_basic_ui'): ?>
<div class="page-edit"> ...
I don't know what to put in that if statement though, in order to say "only print this button if the view has been selected as editable in the views basic ui settings". I'm guessing somebody that reads/writes code better than me could figure it out pretty quick, but I'd appreciate any help I could get.
Thanks.
ps - it's worth mentioning that the users will not have local tabs, so they won't see the 'view' and 'edit' tabs provided by the module.
Not sure exactly what you need, but the bellow code will check if the user has access to the destination and prints the edit link. But better to go with Views' native edit links. Not sure why you can't use them.
<?php
$path = "admin/build/views/edit/VIEW-MACHINE-NAME";
$item = menu_get_item($path);
if ( $item['access'] ) {
print l(t('Edit'), $path);
}
?>
replace VIEW-MACHINE-NAME with View's machine name.
Related
I don't use the Drupal Tabs because they interfere with my CSS but I need the functionality of the Edit tab to be on that screen so that a user can edit the node after reviewing it.
Any ideas on how to do this? Functions? tpl placement? Thanks!
You can do this in a custom module as follows.
In yourcustommodule.module you implement hook_preprocess_node(). In there you check if the user has permissions to edit the node and you set the edit link.
function yourcustommodule_preprocess_node(&$vars) {
if (node_access("update", $vars['node']) === TRUE) {
$vars['edit_link']['#markup'] = l(t('Edit'), 'node/' . $vars['nid'] . '/edit');
}
}
In the node.tpl.php template in the theme you print the edit link if it is available.
<?php if (isset($edit_link)) : ?>
<p><?php print render($edit_link); ?></p>
<?php endif; ?>
If you do not have a node.tpl.php template in your theme folder than copy the one from modules/node.
If you're using the Views Format "Fields", one of the fields that you can add is "Edit Link." It's pretty flexible; it will tell you what text to display in the link. That's probably the preferred option.
If you're not using the "Fields" format, it gets trickier, especially since you're already interfering with some basic drupal styling. I'd need more information about your View and your skill set to recommend a method that doesn't cause more problems.
As a sidenote: I learned Drupal theming from the outside in, and used to use CSS that would interfere with the underlying drupal mechanics like tabs and contextual links. I've moved away from that; I find very few cases where I need to interfere with native styling-- and for those I can use custom .tpl's to get around.
EDIT: Ah. If you're not using views, a custom page .tpl is probably the best way to go. If you're not familiar, the structure for any node edit link is '/node/<NID>/edit' (for clean URL's) or '/?q=node/<NID>/edit' for old-style URL's. Depending on how your path aliases are set up, '/<url-alias>/edit' may work as well but the previous ones are more reliable.
This link on drupal.org gives a few options.
I think u can write a theme file(.tpl) for u specific case and theme page in whichever way u want
I have a wp-network installed with users that can create pages in each site.
Each of those pages get a place in the primary menu, and only one user have permission to create all this menu.
I want to create a user only to be able to edit the content of the pages, but not the title.
How can I disable the title of the page to be edited from the admin menu for a specific user, or (far better) for a capability?
I thought only a possibility, that's editing admin css to hide the title textbox, but I have two problems:
I don't like to css-hide things.
I don't know where is the admin css.
I know php, but don't know how to add a css hide to an element for a capability.
You should definitely use CSS to hide the div#titlediv. You'll want the title to show in the markup so the form submission, validation, etc continues to operate smoothly.
Some elements you'll need to know to implement this solution:
current_user_can() is a boolean function that tests if the current logged in user has a capability or role.
You can add style in line via the admin_head action, or using wp_enqueue_style if you'd like to store it in a separate CSS file.
Here is a code snippet that will do the job, place it where you find fit, functions.php in your theme works. I'd put it inside a network activated plugin if you're using different themes in your network:
<?php
add_action('admin_head', 'maybe_modify_admin_css');
function maybe_modify_admin_css() {
if (current_user_can('specific_capability')) {
?>
<style>
div#titlediv {
display: none;
}
</style>
<?php
}
}
?>
I resolved the problem, just if someone comes here using a search engine, I post the solution.
Doing some research, I found the part of the code where the title textbox gets inserted, and I found a function to know if a user has a certain capability.
The file where the title textbox gets added is /wp-admin/edit-form-advanced.php. This is the line before the textbox
if ( post_type_supports($post_type, 'title') )
I changed it to this
if ( post_type_supports($post_type, 'title') and current_user_can('edit_title') )
That way, the textbox is only added when the user has the capability called "edit_title"
When this IF block ends few lines after, I added:
else echo "<h2>".esc_attr( htmlspecialchars( $post->post_title ) )."</h2>";
To see the page title but not to edit it, when the user hasn't got "edit_title" capability.
Then I had already installed a plugin to edit user capabilities and roles, wich help me to create a new capability (edit_title) and assign it to the role I want.
I can't seem to figure out how to display (echo) a custom field I added to user profiles(via people > account settings > manage fields).
I added a text field called team (field_team). I then clicked manage display and displayed it. It then shows up under there profile page. Great!
However, now I will like to also display that on the frontpage and in the node view as well. How, or where do I do that?
EDIT: I ended up finding this article and this works. http://drupal.org/node/1194506
Code used:
<?php
$node_author = user_load($node->uid);
print ($node_author->roles[3]);
print ($node_author->field_biography['und'][0]['value']);
?>
You must enable devel module to try this:
global $user;
dpm($user);
Hope that helps revealing the new field.
may be someone encountered a similar issue. I output a view on the front page of my D6 site using this code:
<?php print views_embed_view("frontpage_news_list", "default" ); ?>
Yet it seems that this way of outputting the view bypasses content filtering for the teaser field (NOT the view filter, but filters applied to the teaser of the node). I see this because I don't output img's in my teasers, and they are not shown when I check preview in the Views UI, yet on the front page the images are shown in this view.
I have another view, with outputs the nodes of the same type in a "Page" output, and the img's are hidden in the teasers there, as required.
Has anyone encountered a similar issue before? I would appreciate any help with this.
<?php
// you can use block_1, ... blocn_n or page_1,...,page_n as display id
print views_embed_view("frontpage_news_list", "block_1" );
// or this way to show view
$view = views_get_viev(YOU_VIEW_MACHINE_NAME);
$view->set_display($display_id);
// $view->set_exposed_input(array('var' => $myvar)); // to set exposed filters
// $view->set_arguments(array(....)); // to set arguments. rtfm ;)
$view->set_items_per_page(0);
$view->execute();
$result = $view->preview();
print $result;
?>
This was a problem with the HTMLawed module, not with the Views. It has been solved by the developer now, so no issue anymore. Thanks for the help, guys!
I tried to display body content with:
<?php print $node->content['body']['#value']; ?>
However, it doesn't display all body content, it just display first paragraph of body content, sometimes 2 paragraph if it is short :/
I need to print all body. how can I do that?
Thanks a lot! Appreciate helps!
The shortened body content hints on it being filled/rendered for 'teaser' view instead of 'full'. In what context do you issue this print statement?
EDIT: The node templates are usually used for both, teaser and full output, but the decision on what to use, as well as the population of the content entries in the node object happen outside of the node template files. Within the node template file, the variable $teaser will be TRUE, if the node is to be shown as a teaser.
So you need to check in what context your node template gets called, as you'll have to configure that context to render the node as 'full'. This could be in many places, depending on who is responsible to provide the nodes you want to theme, e.g. if the node template gets called from a view, you'll need to configure the view to use 'full page' output, if it comes from a module, you'll need to check with the module settings, etc...
In node.tpl.php try
<?php print $content ?>
However,
<?php print $node->content['body']['#value']; ?>
works for me as well.
To get control over your teaser length the master value is set with Post Settings.
(Length of trimmed posts)
To control this by node type try: http://drupal.org/project/teaserbytype
NOTE: Teasers are cached so you'll need to http://drupal.org/project/retease
However, if you want to just get it done in the node template you could run a node_load() and have everything... but that's not the best practice.
FYI: you can control what CCK fields show up in $content under Display Options.
PS: In teaser mode I often make use of truncate_utf8().