How do I add jquery ui select to a drupal module - jquery-ui

I am porting a plugin I built originally for WordPress to a drupal 7 module.
Everything works fine except I cannot add jquery ui selectmenu:
Here is my .module code
<?php
function mortamCalc_menu() {
$items = array();
$items['mortam_calc/render_calculator'] = array(
'title' => 'Hello World Test',
'page callback' => 'render_calculator',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function render_calculator() {
$module_path = drupal_get_path('module', 'mortamcalc');
drupal_add_css($module_path.'/assets/css/mortamCalc.css');
drupal_add_library('system', 'ui.datepicker');
drupal_add_library('system', 'ui.widget');
drupal_add_library('system', 'ui.selectmenu');
drupal_add_js($module_path.'/assets/js/mortamCalc.js');
ob_start(); // start capturing output
include('views/mortamcalc.php'); // execute the file
$template = ob_get_contents(); // get the contents from the buffer
ob_end_clean();
return $template;
}
?>
ui.datepicker and ui.widget load fine but ui.selectmenu is nowhere to be seen.
What am I doing incorrectly?

Drupal 7 has a ui.selectable library item in the system.module. But I don't think there is any ui.selectmenu library available by default.
Did you add it yourself as a library item, or as part of your module? If that's the case you'd need to update that referencing line to make it work.

Related

How to move SignalR connection scripts to the bottom of the page on Kendo UI MVC grid

I have a kendo grid on a view with signalr connection to back end. It is currently working fine, however, I would like to move the script tag to the bottom of the generated page with a razor #section block.
<script>
var dataCollectionHub;
var hubStart;
$(function () {
dataCollectionHub = $.connection.dataCollectionHub;
hubStart = $.connection.hub.start();
});
</script>
#(Html.Kendo().Grid<ViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
})
.DataSource(
dataSource => dataSource
.SignalR()
.AutoSync(true)
.Transport(tr => tr
.Promise("hubStart")
.Hub("dataCollectionHub")
.Client(c => c
.Read("read")
.Create("create")
.Update("update")
.Destroy("destroy")
)
.Server(s => s.Read("read")))
.Schema(schema => schema
.Model(model =>
{
model.Id("Id");
model.Field("Id", typeof(int)).Editable(false);
model.Field("Name", typeof(string)).Editable(false);
})
)
)
)
The problem is that the grid requires the variables to be defined before itself because I get the following error:
Uncaught Error: The "promise" option must be set.
at new init (http://localhost:61683/Scripts/kendo/kendo.all.min.js:31:9317)
at Object.oe.create (http://localhost:61683/Scripts/kendo/kendo.all.min.js:28:13869)
at new init (http://localhost:61683/Scripts/kendo/kendo.all.min.js:27:22769)
at Function.ie.create (http://localhost:61683/Scripts/kendo/kendo.all.min.js:28:14660)
at init._dataSource (http://localhost:61683/Scripts/kendo/kendo.all.min.js:53:11752)
at new init (http://localhost:61683/Scripts/kendo/kendo.all.min.js:51:10176)
at HTMLDivElement.<anonymous> (http://localhost:61683/Scripts/kendo/kendo.all.min.js:26:4691)
at Function.each (http://localhost:61683/Scripts/jquery-1.12.3.js:370:19)
at jQuery.fn.init.each (http://localhost:61683/Scripts/jquery-1.12.3.js:137:17)
at jQuery.fn.init.e.fn.(anonymous function) [as kendoGrid] (http://localhost:61683/Scripts/kendo/kendo.all.min.js:26:4668)
Is there any way to move the script tag to bottom of the grid without breaking it?
What you're probably after is the Deferring-Feature of Kendo UI. Usually, the Scripts are generated immediately and all variables and JavaScript methods must exist during the initialization.
Update your script:
#(Html.Kendo().Grid<ViewModel>()
.Name("grid")
.Deferred() // Add this to your script
.....
Then move your script to the page bottom, and right after that, put the line:
#Html.Kendo().DeferredScripts();
Please note that deferred initialization might have some drawbacks. You might run into some timing issues when you access the Widgets in JavaScript, they will now be initialized later, also you might notice some FOUC effects.

How we can automatically inject liquid code inside shop's theme using shopify app?

I'm building a Shopify application and I'm interested in automatically adding a liquid content into the shop's theme.
this is the code I use to insert liquid files in active theme.
$asset = $shopify('PUT /admin/themes/' . $id . '/assets.json', array(), array
(
'asset' => array
(
"key" => "snippets/file.liquid",
"src" => "https://yourdomain.com/file.liquid"
)
));
To get the active theme ID i use
foreach ( $themes as $theme){
if($theme[role] == 'main'){
$id = $theme[id];
}
}
Let me know if this helps.

SilverStripe 3.1 GridField file link is re-written with HTML Entities

I'm very new to Silverstripe (3.1). I am using it to collect applications from users. Each user uploads a file which later in the CMS somebody can download.
There is a has_one relationship for the file called 'Document.'
I want to link to that file inside a GridField. So after some searching I did the solution below - easy, and it works except for one problem.
The link does appear inside the correct column in the GridField but it has been converted through something like HTMLSpecialChars() and I can see all the HTML. For the life me I cannot figure how to stop it.
I would like to know where this conversion is taking place?
and how can I circumvent it?
$submissionGrid = new GridField('submissions', 'Submissions', $submission, $config );
$submissionGrid->addDataFields(array(
"Document" => function($row) {
$link = 'Download Document';
return $link;
},
));
You are pretty close.
Instead of addDataFields(), have you tried setFieldFormatting on the configuration of your gridfield?
$submissionGrid = new GridField('submissions', 'Submissions', $submission, $config );
$config = $submissionGrid->getConfig();
$config->getComponentByType('GridFieldDataColumns')->setFieldFormatting(array(
"Document" => function($value, $item) {
$link = 'Download Document';
return $link;
},
));
Depending on the fields available on the Submission Dataobject, if "Document" is something you are adding as a custom column to your gridfield, you will need to add it as well using setDisplayFields(). In this case, add this as well
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
"Document" => "Link to document"
));
What actually worked:
I gave the right answer to jfbarrois for pointing me straight but thought I should post up the code that actually worked because it took me a while to find this answer.
It does have the inestimable advantage that it does actually work and a link is placed in a custom-formatted column in the GridField.
$config = GridFieldConfig_Base::create();
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields($displayFields);
// Adding the custom named 'Download' column to the previously defined $displayFields
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(
array_merge($displayFields, array(
"Download" => "Link to document"
)
));
// Set the field formatting on the custom column inserting the real data from the 'Document' File Object
$config->getComponentByType('GridFieldDataColumns')->setFieldFormatting(array(
"Download" => function($value, $item) {
$link = 'Download Document';
return $link;
},
));
// Create the GridField
$submissionGrid = new GridField('submissions', 'Submissions', $submission, $config );

Translating Breadcrumbs (View Helper) on Zend Framework 2

I´m working in a Zend Framework 2 project and I´m using the View Helper (Breadcrumbs) to inject this navigation component into my views.
To render my Breadcrumbs the following code is used:
<?php echo $this->navigation('Navigation')
->breadcrumbs()
->setLinkLast(false) // link last page
->setMaxDepth(7) // stop at level 7
->setMinDepth(0) // start at level 0
->setSeparator(' »' . PHP_EOL); // separator with newline
?>
I´ve been translating most of the project´s content with the following code
<?php echo $this->translate("Text to translate here", $textDomain); ?>
So applying the same logic to the existing code:
<?php echo $this->translate($this->navigation('Navigation')
->breadcrumbs()
->setLinkLast(false) // link last page
->setMaxDepth(7) // stop at level 7
->setMinDepth(0) // start at level 0
->setSeparator(' »' . PHP_EOL), "navigation"); // separator with newline
?>
Is this the most efficient and/or correct way to translate the breadcrumbs? The text domain here set as "navigation" is where this translation lives. Without being set it defaults to the value "default".
you cannot really do it like this, you're passing html to the translator. simply use these methods on the viewhelper:
$navHelper->setTranslator($yourTranslator);
$navHelper->setTranslatorTextDomain('de_DE');
$navHelper->setTranslatorEnabled(true); // (default)
$navHelper->setInjectTranslator(true); // to pass the translator down to menu/breadcrumbs etc. (default)
To fix the translation of the breadcrumb, I did this :
Cut/paste all the translator configuration into a new file : config/autoload/translator.global.php
I use only one translation file for the entire application and not one by module... but anyway, if you do have one translation file by module, just choose one for your navigation ;)
I modify the base_dir option to the module/application/language :
<?php
return array(
'translator' => array(
'locale' => 'fr_FR',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../../module/Application/language',
'pattern' => '%s.mo',
),
),
),
);
I also put my navigation config array into one autoload file : config/autoload/navigation.global.php
=> I add the new path in the poedit file used to translate my navigation (the only one for me) for automatic detection ;)
In this file, I instanciate a specific translator using the translator's factory method, and I just have to call the translate() method :) :
<?php
$config = require 'translator.global.php';
$options = (array)$config['translator'];
$translator = \Zend\I18n\Translator\Translator::factory($options);
return array(
'navigation' => array(
'default' => array(
array(
'label' => $translator->translate('Home'),
'route' => 'home',
),
[...]
And everything works great now (even breadcrumbs) :)
I had the same translation problem with my forms, and the first trick I found still work great without having to create a new translator for each forrm :
the only trouble was poedit autodetection :
create an underscore function in public/index.php (not used by zend but regognized by poedit)
function _($str){
return $str;
}
and then only have to declare form labels like that :
'label' => _('My Label'),
poedit detects it and translate labels without anything else than a little translation works in poedit for all theses new words ;)
EDIT :
I had a bug in my beadcrumb partial phtml file : didn't call for the translate viewhelper... (just copied it from the zend tutorial and forgot it... stupid isn't it ? :D)
That fixed, the underscore function works as well for the form labels and for navigation... even breadcrumbs ! All my heavy stuff, creating a new translator to call it in the navigation config array is useless :)
I found back where I got this trick inbeetween : => How to translate form labels in Zend Framework 2? (in the last comment... that should be more voted than the actual 0 ;))

Wordpress displaying custom post types and their fields

I have set up a Custom Post Type called 'RELEASES' - think music cd release.
This post type has fields named 'release_artist', 'release_title', 'release_date', 'release_artwork' and 'release_tracklisting' for entering all of the relevant music cd information.
I am having real trouble actually displaying this information in my Wordpress template.
I have really only had luck outputting a list of the titles and none of the other data.
Any idea what I put in the LOOP to display all of the information? Preferably each in its own LIST item so I can style each separately?
Any thoughts greatly appreciated.
You can use get_post_meta to pull in your fields as needed. Inside your loop, you can start with the following:
<?php
$release_artist = get_post_meta($post->ID, 'release_artist', true);
$release_title = get_post_meta($post->ID, 'release_title', true);
?>
<ul>
<li class="release_artist">
<?php echo $release_artist; ?>
</li>
<li class="release_title">
<?php echo $release_title; ?>
</li>
</ul>
Are those custom fields? If yes, try what codex.wordpress.org is saying. Better yet, try ACF plugin.
-- edit
If you want to display parts of your pages on other ones (eg. on your home), you need to use query_posts. This is fairly simple function. For your loop, try something like this:
<?php
global $wp_query;
query_posts(array(
'post_type' => 'releases'
));
while(have_posts()) : the_post(); ?>
<?php $key = get_post_meta($post->ID, 'Opis nazwy'); ?>
<li <?php post_class(); ?>><?php if($key) { echo $key[0]; } else { the_title(); }; ?></li>
<?php
endwhile;
wp_reset_query();
?>
$key is a single value, here set to release_artists. It's purely for testing. If it works - feel free to define your own variables.
You should use:
<?php the_field('field_name') ?>
inside your loop. Hope it helps!
From most of the documentation I've seen online, query_posts shouldn't be the go-to function for creating custom queries and loops. The following code snippet might be a good starting point. You should be able to use this inside or outside of the main loop of your themes template files.
$args = array(
'post_type' => 'release', //remember this is-case sensitive
'posts_per_page' => -1,
);
$releaseQuery = new WP_Query( $args );
if ( $releaseQuery->have_posts() ) :
while ( $releaseQuery->have_posts() ) :
$releaseQuery->the_post();
// Fetching the post ID for demonstration and for use later
$c_id = get_the_ID();
// After running the_post(), alot of the Wordpress functions (not all) can now be used without supplying the post ID.
echo get_the_title();
// You could also have used get_the_title($c_id);
// Then:
echo get_post_meta($c_id, 'release_title', true);
echo get_post_meta($c_id, 'release_artist', true);
endwhile;
endif;
// Return to the current page's main query
wp_reset_query();
// This should now display the page's title
the_title();
About your ID's question:
Every item, like posts and pages in WordPress have an "ID", but they are not normally shown in the lists of them. There are a number of plugins that will add an "ID" column in your admin. Search Wordpress.org for "show ids" and pick one you like. Install it. Activate it. You'll see the ids.
https://wordpress.org/plugins/search.php?q=show+id

Resources