SilverStripe admin input field masking - silverstripe

Is there a way to set a mask to an input field in the SilverStripe admin?
Something like:
$field = new TextField('name', 'Name');
$field->setConfig('mask', '##:##');
I have searched but could not find anything about this.

This isn't an actual "mask" but you can set the new html5 placeholder attribute like:
TextField::create('Name')->setAttribute('placeholder','Name')
If you want a very easy jQuery plugin to do masks, this is one I use often: https://igorescobar.github.io/jQuery-Mask-Plugin/

Related

Add new input field to ACF Link

I am currently trying to add an additional input field where users are able to specify an aria-label inside the already existing link field within Advanced Custom Fields in Wordpress. I’ve attached an image to give a visual representation of what I am looking to do.
Link Modal
Then on the frontend you would use something like $link[aria-label] to get it from the link array.
Any help to achieve this would be amazing. Thank you!
You can try if that field already exists in the ACF link.
Store that link value in a variable and print_r it and check. Check the below code.
<?php
$link = get_field('YOUR-FIELD-NAME');
print_r($link);
?>

Alter field text of the view in Drupal View

I have a view for taxonomy term. And show the list of nodes. I need to alter field text (link element). I try to use views_pre_render hook. in it i do something like this:
foreach ($view->result as $key => &$result);
$result->field_field_show_buy_tickets[0] (it s my field) and in this array I have ['raw'], ['rendered'] and I need to change link title.
It's not very clear from your question what you're trying to achieve.
Assuming you want to change the link text in a view, you could go to the field configuration/settings in your view and try using rewrite options and replacement patterns
Alternatively you could look at views-view-fields.tpl.php and/or template_preprocess_views_view_fields.
Also, check out this discussion

Display multiple field slug types_render_field in wordpress

I create a type group in which I insert an image field with img slug that you can create multiple instances.
Now my problem is that I want to display for example only one field value of img slug field.
Using
types_render_field('img', array())
it show all flied i insert for img slug field.
I also tried with
types_render_field('img[0], array());
but it doesn't work.
Same problem, finally find this solution if someone need :
types_render_field('photos', array("index" => 0));
Instad of using types_render_field I access to custom fields value using get_post_custom function.

How can you hack an existing drupal module and add an entity reference?

I am using imagefield marker and would like the description boxes to load nodes.
Please do not use preprocess. That is for the theming layer.
Use the Field API.
If it's for a particular field on a node edit form, use a form alter to change the array of the form element.
If you wanna modify field behaviour you can use the preprocess field hook in your template.php
template_preprocess_field(&$vars, $hook){
if($vars['element']['#field_name'] == 'myfield')
$variables['loaded_node'] = drupal_render(node_view(node_load($nid)));
}
And then create the theme file field--field-name.tpl.php and print the variable from there.
Hope that helps your question is kinda vague on what you want to do.

Creating a link field in a custom content type

I have several custom content types and in one specific one I need to offer two fields, one for the href for a link, and one for the text of a link this way I can build and style it with minimal user involvement of the HTML/CSS. I also have a custom node.tpl for this content type. My problem is that drupal throws divs around each field I create that aren't in my template file for this content type (node-custom.tpl) and I can't put the href for a link with divs around it inside google.co.uk</div>"> See my problem. Maybe I'm doing this all wrong so any other ideas are welcome.
Please note I'm trying to create this site with minimum involvement of HTML/CSS access for the user. I'm aware I could hand code the link in the field.
The easiest way to do this would be to use a preprocess function in your template.php file and build the link up manually:
function mytheme_preprocess_node(&$vars) {
$node = $vars['node'];
if ($node->type = 'my_type') {
$uri = $node->field_name_of_link_field[LANGUAGE_NONE][0]['value'];
$text = $node->field_name_of_display_text_field[LANGUAGE_NONE][0]['value'];
$vars['my_link'] = l($text, $uri); // Using Drupal's l() function to render a link
}
}
Then in your node template file you'll have access to the variable $my_link which you can output anywhere, and will contain the correct HTML for the link. Finally, go to the "Manage Display" page for your content type and set the display of the two fields you no longer need to output to 'Hidden'.
There are other ways so if that's no good let me know
EDIT
Just to add, I think the easiest way to do this would actually be to install the Link module and use the provided field type instead of the two other fields you're currently using.

Resources