Replace text link with image using php - php

l(t('Edit'), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination())),
I'd like to be able to replace the word "Edit" with an image instead, however when I put an image src in there it shows up as text. Is there a different function I should be using?
I'm using Drupal as my framework.
Thanks ffrom a noob.

Best way to do this is to combine l() and theme_image():
print l(theme_image(array('path' => 'edit_button.png', 'attributes' => array('title' => t('Edit')))), 'node/' . $node->nid . '/webform/components/' . $cid, array('query' => drupal_get_destination(), 'html' => TRUE));
You should also use drupal_get_path() to prefix the path of your image.
This way you will fully apply to the Drupal Coding standards, and make your life easier.

That button should have its own class, for example, action_button or an id such as edit_button. Now use CSS to hide the text and use a background image in its place as shown below:
.action_button, #edit_button {
/* Hide Text */
text-indent: -9999px;
display: block;
background: url('edit_button.png') no-repeat;
/* Set width and height equal to the size of your image */
width: 20px;
height: 20px;
}
EDIT 1:
Change your code with below and use above CSS:
l(t('Edit'), 'node/'.$node->nid.'/webform/components/'.$cid, array('attributes' => array('id' => array('edit_button')), 'query' => drupal_get_destination()));
EDIT 2 [FINAL]:
Passing html as TRUE to array parameter of l() method can make us able to use first parameter as img tag instead of just text for display as link:
l('<img src="edit_button.png" alt="Edit" />', 'node/'.$node->nid.'/webform/components/'.$cid, array('query' => drupal_get_destination(), 'html' => 'TRUE'));

This is the best way I implemented:
list($nodeImage) = field_get_items('node', $node, 'uc_product_image');
$style_array = array('path' => $nodeImage['uri'], 'style_name' => 'MY_IMAGE_STYLE');
$render_node_image = theme('image_style', $style_array);
$render_node_image_WITH_LINK = l($render_node_image, 'node/' . $node->nid, array('html' => TRUE));
print $render_node_image_WITH_LINK

Related

I want to add inline style to YII t(' ')

I want to add style ' float:right ' for this text. I tried some way,but not works. How should i add inline css for this.
public function title()
{
return $this->t('You have {amount} of credit',
array('{amount}' => m('payment')->format(wm()->get('payment.helper')->credit())),
array('style'=>'float:right'));
}
Can you give me a hint, please?
Yii translation function looks like this: Yii::t('category', 'message', \['params' => 'value'\]). So you need style to be in your message to translate it.
Yii::t(
'admin',
'You have <span style="{style}">{amount}</span>',
[
'{style}' => 'color: red;',
'{amount}' => 'Test',
]
);
-> <span style="color: red;">Test</span>
Agree with #Justinas, (Great thanks for your example, it really works) but there one tiny mistake in your code:
'{style}' => 'color: red;' // in this case style would not be applicable to a span
has to be so:
'style' => 'color: red;'
Tested on my case, works for sure.

Drupal-7 rss feed icon to text

I am looking for a way to modify the default Views feed icon from an image to a text value. I have found several cases where people change the default image to a new image, but I prefer working with fonts as they look more crisp regardless of resolution or device.
The idea is to replace the image with a FontAwesome icon (fa-rss-square, &#xf143). I have had succes with changing the default text in the search-block, ie.:
function theme_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'search_block_form') {
$form['actions']['submit']['#value'] = decode_entities('');
}
}
I am a newbie when it comes to php, so my attempts of modifying the hook explained in the Drupal-API has not worked (thus far):
function theme_feed_icon($variables) {
$text = t('Subscribe to !feed-title', array('!feed-title' => $variables['title']));
if ($image = theme('image', array('path' => 'misc/feed.png', 'width' => 16, 'height' => 16, 'alt' => $text))) {
return l($image, $variables['url'], array('html' => TRUE, 'attributes' => array('class' => array('feed-icon'), 'title' => $text)));
}
}
The current output looks like this:
<div class="feed-icon">
<img typeof="foaf:Image" src="mywebsite/misc/feed.png" width="16" height="16" alt="Subscribe to news from my website">
</div>
I'd like to keep the div and its class, but only have the font/text link inside, preferably without the same class. I'd appreciate any clever advice :-)
you could avoid printing the feed icon from php and just enter the html code either in the footer or the header of the view from the UI
or
you could hide the image via CSS, and use
.feed-icon:before {
font-family: FontAwesome;
content: "\f143";
}

Specify Image Height and Width in php string

I have a linked image that I need to specify height and width html attributes for that is generated by php string. I've looked into using getimagesize but its not looking like what I need. I am currently using social engine.
This is the string I have that calls the image link.
<?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'null'), array('class' => '')) ?>
which outputs html somthing like <img src="#" class="null"/>
I need to modify the php to create an image that is specified to be 110px x 110px
ie <img src="#" class="null" width="110" height="110"/>
Can anyone give me an example of how I could write my string?
You have to use this:
<?php echo $this->htmlLink(
$item->getHref(),
$this->itemPhoto(
$item,
'null',
null,
array('width' => '110px', 'height' => '110px')),
array('class' => '')
) ?>
That is, add a fourth parameter array to itemPhoto function.
Socialengine is an extension of Zend framework. You should try to check out the definition of itemPhoto, htmlLink etc. functions in order to customize them. For example itemPhoto can be found here- \application\modules\Core\View\Helper\ItemPhoto.php
The last parameter is used for that, isn't that?
$this->htmlLink(
$item->getHref(),
$this->itemPhoto($item, '', '', array('width' => 110, 'height' => 110)),
array('class' => '')
);
Method1:
Just add style for null class
<?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'null'), array('class' => '')) ?>
as:
.null {
height: 110px;
width: 110px;
}
Method2:
Or you can pass a inline style attribute as:
<?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'null'), array('class' => '', 'style' => 'height: 110px; width: 110px')) ?>
I cant see whats behind the function htmlLink() but I guess due to the name of those elements you pass you could just write.
echo '<img src="'.$this->itemPhoto($item, 'null').'" class="null" width="110" height="110"/>';
but ether post that function or just try and error!

Make wp_tag_cloud look like cloud (the words should overlap)

Can I get wp_tag_cloud (http://codex.wordpress.org/Function_Reference/wp_tag_cloud) to look like either of these two pictures?
This is how it looks like today: site
This is the php I'm useing:
<?php
$args = array(
'taxonomy' => 'category',
);
wp_tag_cloud($args);
?>
But when I add 'orderby' => 'name' for example, the page goes blank.
Picture two http://paul.kedrosky.com/WindowsLiveWriter/ATagCloudintheLifeofCNBC_E14B/cnbc-cloud_thumb.png
the tag cloud WILL look like this , but it depends on your theme , or more precicely , the CSS that is assigned to the #tag_cloud ID.
If your tag cloud looks different now, you should edit your css to suit your needs , for example :
#tag_cloud a:link {
font-family: georgia;
color: red;
}
#tag_cloud a:hover {
font-family: georgia;
color: green;
}
#tag_cloud a:visited {
font-family: georgia;
color: blue;
}
also , wp_tag_cloud() function can recieve parameters , like
smallest' => 8,
'largest' => 22,
'unit' => 'pt',
'number' => 45,
where smallest is the size of the smallest tag (less frequent) the larget is the largest size, the unit is the units used for that numeric value of size , and the number is the number of tags in the cloud .
Probably your theme has modified either the css or the function parameters .
You can read more here : http://codex.wordpress.org/Function_Reference/wp_tag_cloud
If you are not familiar with CSS or PHP, I suggest you would read some more , or post the direct link to your problem and aske for someone to help you fix it .
The solution became something like this:
.tag-link-10 {font-size:13px !important;text-transform:lowercase;}/* Annons /
.tag-link-5 {font-size:16px !important;text-transform:uppercase;font-style:italic;}/ Film */
I had to style each tag separately. Though i didn't get them to overlap.

CK Editor - assigning ID

I am trying to get CKEditor to use an unique ID that I can use some jQuery to grab the value within a ajax request.
Can anyone suggest how I can set the ID for the editor?
Below is the code
http://pastebin.com/eTP7xnKr
Try something like this, you can also set many other attributes:
$CKEditor->textareaAttributes = array("id" => $fieldname, "cols" => 40, "rows" => 4, 'style' => "width: {$width}; height: {$height}; position: relative; overflow: auto;");
Have a look in ckeditor.php it will tell you how.
Sorry, I don't have a clever answer...

Categories