I install and override template in knp pagination. But I need show how many pages are. For example: 1 page of 10, 5 page of 10 e.t.c?I read offical documentation but I dosen't find ansver.
You can override this template : https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/views/Pagination/sliding.html.twig
Just use the variable pageCount to display the amount of pages where you want.
To do so, create a sliding.html.twig file in your app/Resources/KnpPaginatorBundle/views/Pagination folder.
I can see at the doc this abstract pagination class : https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Pagination/AbstractPagination.php
This class has a method on line 113:
/**
* Get total item number available
*
* #return integer
*/
public function getTotalItemCount()
{
return $this->totalCount;
}
Related
In Drupal 9, I can create a new field called file in some content type, e.g. in Article.
Then for this new field in Manage Display I can select Format Settings: File Table.
Finally, I can add a new page (Article type) and attach some files.
After saving, I have a page with a table.
My question: how do I add a class to this table? I know I can add styles in css stylesheets, but maybe there is a way to add a class directly to the table in a node?
I mean node not View. It just so happens that for View I already know how to do it. But I don't know how to do this for Node
Thank you
ok
The hooks are there for that. If you want to update the node renderable array, you can use the preprocess hook :
/**
* Implements hook_preprocess_HOOK().
*/
function my_theme_preprocess_node(&$variables) {
/** #var \Drupal\node\Entity\Node $node */
$node = $variables['node'];
if ($node->bundle() == 'article'
&& $variables['view_mode'] == 'full') {
// $variables['content']['files']['#attributes']['class'][] = 'your-class';
}
}
In your case, you want to update the field, it might be cleaner to edit the field directly :
/**
* Implements hook_preprocess_field().
*/
function your_theme_preprocess_field(&$variables, $hook) {
$element = $variables['element'];
}
I am using sonata e commerce bundle and I have added a couple of products. I can get them list and displayed in the admin section but when I try to create a new product I only see the basic field that all the products have.
Is there any way to create an Admin class that will allow me to see the extra fields for each kind of product class?
I finally figured out how to do this looking into the sonata sandbox example.
To add the custom fields to the product in the admin I have to override the WineProductProvider class and add the following method just like an admin class.
/**
* {#inheritDoc}
*/
public function buildEditForm(FormMapper $formMapper, $isVariation = false)
{
parent::buildEditForm($formMapper, $isVariation);
$formMapper
->with('Bottle details')
->add('origin','text')
->add('year','integer')
->add('grapes','text')
->add('closure','text')
->add('food','text')
->add('style','text')
->add('size','integer');
$formMapper->end();
}
And thats it. Hope it helps someone else.
I am developing a custom module in Drupal 8. It shows data regarding some organizations that make use of our service. For this I have created a Controller that shows data from the database, which is put there by another module. From the scarce information and tutorials available on Drupal 8 developement I've been able to create the following. In the .routing.yml file I have created a path to this overview table like so (it doesn't properly copy here but the indents are okay):
OrganizationOverview.world:
path: '/world'
defaults:
_controller: 'Drupal\OrganizationOverview\Controller\OrganizationOverviewController::overview'
_title: 'World'
requirements:
_role: 'administrator'
_permission: 'access content'
So now the overview is accessible with the URL site.com/world. But what we want is to show it on the frontpage or show it anywhere else on the site. For this it needs to be a Block. For this I have created an OrganizationOverviewBlock class in OrganizationOverview/src/Plugin/Block/OrganizationOverviewBlock.php which is the proper way according to the PSR-4 standard. The class looks like this:
<?php
namespace Drupal\OrganizationOverview\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Session\AccountInterface;
/**
* Provides a 'OrganizationOverviewBlock' block.
*
* #Block(
* id = "organization_overview_block",
* admin_label = #Translation("OrganizationOverviewBlock"),
* category = #Translation("Custom")
* )
*/
class OrganizationOverviewBlock extends BlockBase
{
public function build()
{
return array(
'#markup' => 'Hello World',
);
}
public function blockAccess(AccountInterface $account)
{
return $account->hasPermission('access content');
}
}
So now it should show up in the Blocks Layout page (after flushing cache, which I do consistently) at site.com/admin/structure/block/ as "Organization Overview Block" where I should enable it, according to plenty sources (Create custom Block, Block API Drupal 8). But it doesn't show up there. I've tried implementing ContainerFactoryPluginInterface with some of those methods but that changes nothing. It does not show up. I've tried making a new test module with a block with the same code but a simpler name and it does not show up. I've copied the code to another platform (the production site) but it also doesn't show up there. What am I doing wrong? Can someone help me? I know Drupal 8 is new but this module really needs to be published soon.
You'll find a working example of building custom block in the Drupal Examples Project. So:
Get the Drupal 8 examples project
Enable the Block Example Module
Double check the working code
With that, you should get your block available in your own module
You can also take advantage of what explained here, where a single php file do the all job. Check files and folders path also.
Not require routing file for custom block.
<pre>
class TestBlock extends BlockBase {
/*
** {#inheritdoc}
*/
public function build() {
return array(
'#markup' => $this->t('Welcome page!'),
);
}
}
</pre>
http://drupalasia.com/article/drupal-8-how-create-custom-block-programatically
You should respect the Drupal coding standard recommendations:
No camelCase naming convention in module name.
OrganizationOverview actually is an error, you should use organization_overview (lowercase/underscore) naming conventions.
As you know there is an admin page for setting up hierarchy of terms by dragging it, which can be found on admin/structure/taxonomy/your_vocabulary. Underneath the table there are two buttons "Save" and "Reset to alphabetical". Now I need to interact with those sumbits by using some hook but I've no idea how to do it. I've already tried hook_taxonomy_term_presave() and hook_taxonomy_term_update(), but those are definitely not appropriate. Any ideas how to hook it?
You can do all your stuff by adding additional callback in submit.
e.g:
/**
* Implements hook_form_FORM_ID_alter().
*/
function hook_form_taxonomy_form_vocabulary_alter(&$form) {
$form['#submit'][] = 'my_function';
}
function my_function(&$form, &$form_state) {
// Do something ..
}
I'm currently coding a WP plugin and would need to override templates.
My filter hook looks like that - and it executes:
add_filter('template_include', 'mcd_set_template',10);
function mcd_set_template() just returns the required path as string - or the default WP template in case the file not exists.
I'm toying with this for hours already, even could include that alternate template (but it appears at the bottom of the page).
So my question is, how to force WP 3.2.1 to just load another template file instead - and which priority is required??
Update:
Also I noticed when using var_dump ... it outputs almost at the end of the file - but should appear before the opening HTML tag...
According to this ticket it should work with template_include hook: http://core.trac.wordpress.org/ticket/11242
Or is the only way to hook these filters instead:
http://codex.wordpress.org/Template_Hierarchy#Filter_Hierarchy
?
You could use template_redirect as shown above, but that does require exit, and it does trample on everything else WordPress would normally do to find the current template. You may want to let that happen and then apply logic to the current template.
Using some of what is above...
add_action('template_include', 'mcd_set_template');
function mcd_set_template() {
return locate_template('templatename.php');
}
That is fairly simple, you can also pass an array to locate_template() to define a hierarchy. If you were to use 'template_redirect as shown above, you should still be using locate_template, and this is how.
add_action('template_redirect', 'mcd_set_template');
function mcd_set_template() {
/**
* Order of templates in this array reflect their hierarchy.
* You'll want to have fallbacks like index.php in case yours is not found.
*/
$templates = array('templatename.php', 'othertemplate.php', 'index.php');
/**
* The first param will be prefixed to '_template' to create a filter
* The second will be passed to locate_template and loaded.
*/
include( get_query_template('mcd', $templates) );
exit;
}
Finally, the best way would be to filter specific types instead of the whole hierarchy. For example you could filter 'category_template' or 'page_template'. That would be more specific, it would avoid messing with the whole template hierarchy if you don't want to - and it lets WordPress do more of the heavy lifting
For example:
add_filter('category_template', 'filter_category_template');
function filter_category_template($template){
/* Get current category */
$category = get_queried_object();
/* Create hierarchical list of desired templates */
$templates = array (
'category.php',
'custom-category-template.php',
'category-{$category->slug}.php',
'category-{$category->term_id}.php',
'index.php'
);
return locate_template($templates);
}
You can of course create that array of hierarchical templates any time you use locate_template(). Using this method, its easy to see how easily you could create all sorts of very detailed and specific hierarchies either as part of or separate from the native Template Hierarchy.
Have you tried using an add_action instead? For example, you might want to try something like the following in your plugin:
add_action('template_redirect', 'mcd_set_template');
//Redirect to a preferred template.
function mcd_set_template() {
$template_path = TEMPLATEPATH . '/' . "templatename.php";
if(file_exists($template_path)){
include($template_path);
exit;
}
}
Here is a helpful reference: http://www.mihaivalentin.com/wordpress-tutorial-load-the-template-you-want-with-template_redirect/