texts: How to show and hide menu tabs in module

texts:
I have created tabs in module for different functions. As per code shown below, all the tabs are shown simultaneouly when I login to the module. But, I want to show specific modules depending on the play formats, how can I do that? I tried hook for menu_alter and created custom module but all hides specific menu directly and not condition wise.

Play URLs

$items['abc/play'] = array(
    'title' => t('Welcome Player'),
    'access arguments' => array('administer users'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('score_entry_table'),
    'access callback' => TRUE,
    'file' => 'scoreentry.inc',
);

$items['abc/play/cricket_score'] = array(
    'title'         => t('Cricket Scoreboard'),
    'page callback' => 'cricket_score_table',
    'page arguments' => array(1),
    'access arguments' => array('administer users'),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
    'file' => 'cricketscore.inc',
    'weight' => 2
);
$items['abc/play/soccer_score'] = array(
    'title'         => t('Soccer Scoreboard'),
    'page callback' => 'soccer_score_table',
    'page arguments' => array(1),
    'access arguments' => array('administer users'),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
    'file' => 'soccerscore.inc',
    'weight' => 1
);

Now it shows both tabs after login, I want to show only one tab as per format. I go to scoreentry page, where I get the format code and I want to hide the tab based on that format.


texts: I am using rules and want to access a field in a users content profile. how can I do this?


texts: List two next nodes according to current one

texts:
I need to add Views block on node page of one content type and there I need to show two next nodes by date (older than current) according to the date of current node's creation date.

How I can accomplish this?


texts: Having multiple active config splits causes main configuration directory to be ignored

texts:
I'm trying to have a config setup for a multisite, so that I have following config directories:

default - common config
dev - split for dev environment
local - split for local environment
<site> - split for a site

When I'm working on a local copy of the site, this means I have local and <site> splits active at the same time. I've experienced, that all the configuration apart from that blaclisted in local was then exported (when running drush cex) to the <site> split, so default directory is empty. How can I override this behavior, so that <site> split would contain only specified graylisted configuration?


texts:
I'm looking for a way to change the text ' | Drupal' part from the  tag for all pages to ' | ToAnyThing'. I guess it should be possible to achieve this in the admin interface somewhere, but I cannot find where.

Thanks.


texts: Display a message to user for empty user fields

texts:
User's have a field called "Location" (uses the Address module).

I would like to show a message (or enable a block) to users that have not filled out this field.

Specifically, this message should be shown when they log in, view their profile, or when they view their dashboard.

I am attempting to do this with Rules, but no luck yet. Any guidance would be appreciated.


texts: how to change the background image based on the node (the hard way)

texts:
I'm trying to change the background image of my site based on what node the user is viewing (not just what node type, but specifically what node). I have added an image field to my node type called background image. Basically, I'm trying to go into my html.tpl.php file and inject a style right into the body tag, for isstance

background-image:url('../images/mybg.jpg');

I'm hoping to grab the image field from node that is loaded, but I'm having trouble figureing out hoe to access a nodes field from the html.tpl.php file (i need to do it from here becuase that's where the body tag is). I've added a pre-process function to my template to try and find the correct field, but i've hit a dead end

function mytheme_preprocess_html(&$vars) {
     dpm($vars);
}

the array that is traced makes no sense to me, and I'm unable to find the field. Is there a better way to do this


texts: How to make modal dialog submit buttons work when called with OpenModalDialog()?

texts:
I'm having an issue with some modal dialogs in Drupal 8.3.5. My requirement says that when I'm on a particular form under a particular condition, then a modal dialog pops up and collects some additional information.

I can open the dialog, but I can't make the form actually do anything once it's up. Clicking the submit button doesn't actually fire anything on the server, but I do get "An AJAX HTTP error occurred".

The form itself is pretty simple:

public function buildForm(array $form, FormStateInterface $form_state, $options = NULL) {
  $form['#prefix'] = '
';
  $form['#suffix'] = '
';

  // The status messages that will contain any form errors.
  $form['status_messages'] = [
    '#type' => 'status_messages',
    '#weight' => -10,
  ];

  // A required checkbox field.
  $form['our_checkbox'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('I Agree: modal forms are awesome!'),
    '#required' => TRUE,
  ];

  $form['actions'] = ['#type' => 'actions'];
  $form['actions']['send'] = [
    '#type' => 'submit',
    '#value' => $this->t('Submit modal form'),
    '#attributes' => [
      'class' => [
        'use-ajax',
      ],
    ],
    '#ajax' => [
      'callback' => [$this, 'submitModalFormAjax'],
      'event' => 'click',
    ],
  ];
  $form['#attached']['library'][] = 'core/drupal.dialog.ajax';

  return $form;
}

Here's the thing, though. When I open this form with a link, it works. When I open it with an OpenModalDialogCommand(), it doesn't.

The link that opens the form successfully and lets it submit:

$form['open_modal'] = [
  '#type' => 'link',
  '#title' => $this->t('Open Modal'),
  '#url' => Url::fromRoute('modal_form_example.open_modal_form'),
  '#attributes' => [
    'class' => [
      'use-ajax',
      'button',
    ],
  ],
];

And here is the OpenModalDialog() command that opens the form but doesn't let it submit:

function submitModalFormAjax(array &$form, FormStateInterface $form_state) {
  $response = new AjaxResponse();

  // Get the modal form using the form builder.
  $modal_form = \Drupal::formBuilder()->getForm('Drupal\modal_form_example\Form\ModalForm');

  // Add an AJAX command to open a modal dialog with the form as the content.
  $response->addCommand(new OpenModalDialogCommand('My Modal Form', $modal_form, ['width' => '800']));

  return $response;
}

Am I using the OpenModalDialog() wrong? Is there something I'm missing on my form to make it work correctly? Is there a different way I'm supposed to be calling the form?

How can I make my modal dialog submit buttons work when I call it with an OpenModalDialog() command?


texts: How to change the order of form elements in a modal user login form

texts: I have a modal form for user login. I want to rearrange the links. I enabled captcha for user login form. Now i want to display 'Create New Account' and 'Forget Password' links to be displayed below the 'Login' submit button. I need help on how to do this. Thanks in advance.


texts: How to change the way a Content Type is displayed depending on user?

texts:
I'm currently trying to create a Massively Multi Onlineplayergame (see tribalwars.net) in Drupal while learning it. To do this I want to be able to change the way a content type is displayed depending on what user is looking at it.

Say for example, if it's the current owner of the "town" I want the user to be able to edit it. While if it's not the owner I want the user to be able to send troops there.

I've been looking at events but there doesn't seem to be any event that allows me to do that sort of thing. Will I have to define a content type programmatically or is there any other way to do it?


texts: How can I overwrite taxonomy field link output?

texts:
I am using Drupal 7 and the Views module. I made a very simple page showing nodes with the Views module, where I want to show only one field, which contains taxonomy terms.

I want to rewrite standard link from this page to my own variant. I selected "Rewrite results" and wrote my link. In the view, those links are not changed: they are going to taxonomy term pages.

I know that if I used a view showing taxonomy terms (not nodes), I could checkout the field for standard taxonomy output, but in a node view there is no such possibility.


texts: How to use hook_url_outbound_alter for emails only?

texts:
I have a Rule set up that sends a mail to a certain user with a link to a certain node. This link is altered using hook_url_outbound_alter to include additional details.

The problem is that hook_url_outbound_alter also alters the URL everywhere else. Closing an overlay on the node view page rewrites the URL, clearing the cache (admin toolbar + devel) on the node pages rewrites the URL and so on.

I already attempted to check for an absolute URL in $options, but that does not solve the problems above.

function mymodule_url_outbound_alter(&$path, &$options, $original_path) {
  if (preg_match('|^node/([0-9]*)|', $path, $matches) && $options['absolute'] {
      $options['query']['parameter'] = $foo;
    }
  }
}

Can I use hook_url_outbound_alter() to only alter URLs when it was invoked from a specific module or something?


texts: Display block based on main content type with view

texts:
I have created a view in a block, to display some related information to the current content type being displayed into the block. More precisely, I want to display the block only for book pages.

What I did is to add a contextual filter based on content type.
For "WHEN THE FILTER VALUE IS NOT AVAILABLE", I provide a default value for "PHP contextual filter code" as follows

$node = node_load(arg(1));
return $node->type;

For "WHEN THE FILTER VALUE IS AVAILABLE", I use "Specify validation criteria" for content types with "book page".

I tried this but it didn't work. I think because I am using aliases in the url, it does not work.

What am I missing?

P.S: My final goal is actually to extract the group audience from the current book page and display the admins of that group into the block.


texts: How to restrict previous date display in custom forms?

texts:
I created a custom module for a form which accepts from date and to date as user input. I would like to restrict the user from selecting a date prior to current date.

Code snippet of my code

$form['oneway']['from_date'] = array (
  '#type' => 'date',
  '#title' => t('From Date'),
  '#date_year_range' => '-80:0',
  '#required' => TRUE,
);

Can someone please help me out?


texts:
I'm going to make a sign-up website. When the user has clicked on Sign-up link it will take them to this pop-up window on the browser itself giving them one option (to input mail) then a submit button. I know how to setup the thing in webform but how do I make a sweet pop-up window for the user to enter the value? Is there any module for this?

Any suggestions are welcome

thanks


texts: How to import the webform without changing the node id ?

texts: I am trying to import a webform from another drupal installation, but it was changing the node id of the webform. How can i preserve the node id of the webform ? Is there any module for importing without changing the node id


texts: Drush missing the "provision" and "Hostmaster" commands

texts:
One of our boxes is missing these Aegir-Drush commands (from drush help):

All commands in provision: (provision)
 backend-parse         Parse the output of --backend commands to a human readable form
 hostmaster-install    Install and verify the Hostmaster frontend.
 hostmaster-migrate    Migrate an instance of the Hostmaster front end to a new platform
 provision-backup      Generate a back up for the site.
 provision-backup_del  Delete a backup file.
 ete
 provision-clone       Clone a site between platforms.
 provision-delete      Delete a site.
 provision-deploy      Deploy an existing backup to a new url.
 provision-disable     Disable a site.
 provision-enable      Enable a disabled site.
 provision-import      Turn an already running site into a provisioned site.
 provision-install     Provision a new site using the provided data.
 provision-lock        Lock a platform from having any other sites provisioned on it.
 provision-login_rese  Generate a one-time login reset URL.
 t
 provision-migrate     Migrate a site between platforms.
 provision-restore     Restore the site to a previous backup. This will also generate a backup of the site as it was.
 provision-save        Save Drush alias
 provision-unlock      Unlock a platform so that sites can be provisioned on it.
 provision-verify      Verify that the provisioning framework is correctly installed.

We're able to log into Aegir via the web interface, but none of the commands work. The best we could tell, the install went fine. I think it might be related to these commands missing from our server.

How do I get these commands back? We were able to verify the Hostmaster platform with no problem.


texts:
I have 2 content types named All Events and Event. Event as the name is self descriptive it represents an single event (programme). Whereas All Events contains additional data related to events, that is not part of any single event.

I need to have a relationship which says 'Featured Event'. And that relationship is going to be one-one. What would be the best way to select featured event among those events?

To organize this I can create a field collection field where each collection represents an event. And again selecting featured content would be question. Having a field in event to make it featured won't work, since 'one-one' wont be respected by the system and user need to take care of it.


texts: Why does the title callback of /user produce the title for /user/register?

texts:
I'm a bit puzzled why the title callback of /user produces the title for /user/register and /user/password.

When I set the title callback of /user, I see this affects the title of /user/register and /user/password. However, setting a title callback for /user/register seems to make no difference; it appears to stick to the title callback of /user.

What is special about /user/register and /user/password which results in titles for these callbacks to have their titles produced by the title callback of /user?

function mytheme_menu_alter(&$items) {
  $items['user']['title callback'] = 'mytheme_user_title';
}

function mytheme_user_title($title) {
  return 'test';
}


texts: How do I theme the core modal with twig?

texts:
Drupal 8 comes with built in modals.

This works:

modal

How can I style that modal using twig, to add new classes to the box? The intention is to take over the bootstrap style language.


texts: How do I display a view pane with all items of a category?

texts:
I created an Events content type.
I created a vocabulary that has two category terms, Events and Plays.

I have a view that contains a list of all content of type Events.

Each Events listing displays with the category term as the title/link.

The link should go to a page that has a content pane containing a list of all of the Events with that tag.

So, the view looks something like,

Movie (term)

movieName

movieTime

Play (term)

movieName

movieTime

Movie (term)

movieName

movieTime

Play (term)

movieName

movieTime

Movie (term)

movieName

movieTime

The term field is configured to be a link.

If I click on Movie or Play I want to go to a page that has a content pane containing a list of all of the Events tagged with Play or Movie, depending on which I clicked.

On the view, I set up a Contextual filter:

Content: Has taxonomy term ID

I set up a Relationship:

Content: Taxonomy terms on node

How can I set up this view so that clicking on the category will take me to another page with a view/content pane that displays a list of Events based on that tag?


texts: How do I move a group of nodes to another Drupal instance?

texts:
What:
I'm breaking a part a huge D7 site into a D7 multi-site instance.

Why:
Marketing demands have changed. They different units still want to use the same theme but have different main menus and slight CSS tweaks here and there. They also want separate authors and very different approval processes. This site is crippled under it's own weight.

So far: I've already copied over Content Types via Bundle Copy and most everything that will remain standard via source controlled features.

How/Question: How can I move a piece of content (node/XXX) to another Drupal 7 instance?  A drush solution would be preferred so that I have the ability to script this across Stage and Production servers once we figure it out on Dev.

Errata:
I've seen interesting methods to scrape content via feeds, sharing content, and seen great dev to prod workflows. However, I haven't seen something that addresses a one-time move of a node between instances.


texts: How to restrict users to view their own custom content type?

texts:
I am developing a custom module called 'serviceentry' which also exposes a custom content type called 'serviceentry'.

I also exposes the custom permissions as :

function serviceentry_permission() {

        return array(
           'view own serviceentry content' => array(
            'title' => t('view own serviceentry content'),
            'description' => t('view own serviceentry content')
        ),
        'view any serviceentry content' => array(
            'title' => t('view any serviceentry content'),
            'description' => t('view any serviceentry content')
        ),
        'create serviceentry content' => array(
            'title' => t('create serviceentry content'),
            'description' => t('create serviceentry content')
        ),
        'edit own serviceentry content' => array(
            'title' => t('edit own serviceentry content'),
            'description' => t('edit own serviceentry content')
        ),
        'edit any serviceentry content' => array(
            'title' => t('edit any serviceentry content'),
            'description' => t('edit any serviceentry content')
        ),
        'delete own serviceentry content' => array(
            'title' => t('delete own serviceentry content'),
            'description' => t('delete own serviceentry content')
        ),
        'delete any serviceentry content' => array(
            'title' => t('delete any serviceentry content'),
            'description' => t('delete any serviceentry content')
        ),
        'administer serviceentry' => array(
            'title' => t('administer serviceentry'),
            'description' => t('administer serviceentry')
        ),

        );
    }

Then, I check for permissions using following function.

function serviceentry_node_access($node, $op, $account) {
    $type = is_string($node) ? $node : $node->type;

    if (in_array($type, node_permissions_get_configured_types())) {
        if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
            return NODE_ACCESS_ALLOW;
        }

        if ($op == 'view') {
            if (user_access('view any ' . $type . ' content', $account) || (user_access('view own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
                return NODE_ACCESS_ALLOW;
            }
        }
        if ($op == 'update') {
            if (user_access('edit any ' . $type . ' content', $account) || (user_access('edit own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
                return NODE_ACCESS_ALLOW;
            }
        }

        if ($op == 'delete') {
            if (user_access('delete any ' . $type . ' content', $account) || (user_access('delete own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
                return NODE_ACCESS_ALLOW;
            }
        }
    }

    // Returning nothing from this function would have the same effect.
    return NODE_ACCESS_IGNORE;
}

Now, I want to restrict users to view nodes of serviceentry based whether they have 'view own serviceentry content' or 'view any serviceentry content' permissions. The above code is not working as Drupal is not passing $op='view' in order to restrict the user. If user has 'access content' permission, then all nodes are shown otherwise not. I want to have finer control over my own node type. How to do that?


texts:
I am using hook_form_alter() in  Drupal 6, which successfully works. As for now, when I submit the form, it again runs the same hook. I want to run it only on load and edit.

Do you have any idea on how I do this?


texts: Can I use the first value of a multivalue field as another field? ("Cover" use case)

texts:
My content type uses an unlimited number of images as "screenshot".
I would like to be able to manage the FIRST screenshot of the set as the "cover" of the content type, so to define a "field_cover" and telling Drupal "The value for this field is the first value of field_screenshot".
In this way I could reference field_cover in my views for some special cases (like showing the latest mynodes in home page, using the "cover" as the image).


texts: What's the prupose of the version property of a theme library?

texts:
Reading the 2 articles below, I'm creating a new theme.

Defining a theme with an .info.yml file
Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme

In the example below, I don't understand what is the purpose of the version property of the global-styling library :

global-styling:
  version: 1.x
  css:
    theme:
      css/layout.css: {}
      css/style.css: {}
      css/colors.css: {}
      css/print.css: { media: print }

Is it a reference to the site version with which this library is compatible ?

Is it the version of the library itself ? And in this case, when will it be used and for what ?


texts: Using hook_form_alter on exposed view filters on Drupal 7

texts:
I'm having some trouble using hook_form_alter() with Views 3 and Drupal 7.

I'm unable to add an if statement to uniquely identify a view; whatever I put in, the if statement is never found to be true. However, I can easily use the form_id using the following so I'm not sure where I am going wrong!

if ($form_id == 'views_exposed_form') {
}

How do I use hook_form_alter() to uniquely alter a single view of mine?


texts:
Use Case - I've got several Dashboards (some custom View pages) in the site. Depending on the Role associated with a User, I want to direct them to thier respective Dashboard.

So an Editor would go to the Editor Dashboard, a Contributor would go to a Contributor Dashboard, etc. after they login.

(I'm using the OpenPublic distro)


texts: I have installed search configuration module to alter pagination on search results. I've set the pager limit in Configuration > Search settings > ADDITIONAL NODE SEARCH CONFIGURATION > RESULTS to 3 (which should trigger pagination), but no pagination is appearing when I am logged in whereas when I am logout, it is showing pagination having 2 items per page instead of 3.


texts: How to give access to view all unpublished comment for any role?

texts:
I have a one role forum admin. This role manage the all comment published/unpublished.

To manage I have created the comment view and listed all published or unpublished comment.

My issue is when forum admin click on published comment it's showing but when he click on unpublished comment the comment not showing.

I want to view also unpublished comment to forum admin role.
How can give this permission to forum admin role.


texts:
I am a newbie to Drupal 7.21.
I have got as far as creating a rotating banner for my front page.  Now I want to have a clickable link from each banner to a new page that gives more information about each banner topic.  The banners automatically pause nicely when the mouse hovers over them, but I can't find a way to get the link attached to the image.
Can anyone help?
Thanks
Andy


texts: Why do all product display nodes with same referenced product (SKU) appear in 1 order view

texts:
Each time an order is added to cart, the admin/commerce/orders/11/view, for example, shows all product display nodes ever created on the site for that SKU.

I suspect that this is not the normal behaviour I should see because if it were, over time, these order views on the administrative pages would grow endlessly long.

However, the Cart Form shows only 1 item and that appears to be correct. I suspect there is something incorrect with my Line Items view.  admin/structure/views/view/commerce_line_item_table/edit/default?destination=admin/commerce/orders/11/view

Please see my attached images.


texts: How to fix Bootstrap theme overlapping on views administration pages

texts:
Using bootstrap as an administration theme. Required rather than seven because of the way we are getting people to contribute to the site.

Under views contextual filters, they layout falls apart. Anybody solved this? See under "Path component".

I have tried debugging the page and setting clear:both everywhere etc.


texts: Using taxonomy to give option of page layout - working but showing error (Notice: Undefined variable: node in include())

texts:
I have been building a site in Drupal 7. I have the content type "Basic Page" but added taxonomy terms for the user to be able to select "Standard" or "Full Width" page.

If the user selects "Full Width" the page.tpl.php file has some code which recognises the value chosen for the page removes a sidebar (usually seen on the "Standard" page).

It is working perfectly on the frontend but has an error in the backend.

Here is the code in the page.tpl.php page:

<?php $field_page_width = field_view_field('node', $node, 'field_page_width'); ?>

            <?php if ($field_page_width['#items'][0]['taxonomy_term']->name == 'Standard') { ?>

                    <?php print render($page['content']); ?>

                    <?php print render($page['side_content']); ?>

            <?php } else { ?>

                    <?php print render($page['content']); ?>

            <?php } ?>

I am receiving this error:

  Notice: Undefined variable: node in include() (line 76 of /home/public_html/sites/all/themes/zen/child_theme/templates/page.tpl.php).

Why do I get this error? Do I need to have something which establishes $node in the template.php file?


texts: Drupal 7 - Destroying the session when the browser closes is not working on Chrome

texts:
Is there an issue with destroying the user session using Chrome? I've set this setting in settings.php: ini_set('session.cookie_lifetime', 0) but it seems like Chrome ignores it or is it just caching the user session itself.

On IE and FF this works as intended. I've even set Chrome to not save user credentials but to no avail.

Any ideas please?


texts: How to build my own view for apache solr module

texts:
After successful integration of apache solr module in drupal 7 and displaying the result Ii found that it is using the view files (search-results.tpl.php & search-result.tpl.php) from the core search module to display the result.

How can I use my custom files similar to (search-results.tpl.php & search-result.tpl.php) inside the apache solr module folder to display the result?

Since I am new to drupal and just started can somebody guide me to implement it.


texts: Post in group after import, only when field has same value

texts:
I have two contenttypes:
A which is a group-type
B which is a grouppost-type

Both grouptypes contain a similar field: color

All my group-posts will be imported using feeds and should then be posted into the groups.
HOWEVER only when the color field on both grouptypes contains the same value.

I am no php expert, can rules offer a solution for this usecase?

Thanks


texts: Change module pattern to allow numbers at start of word

texts:
I am using the Hashtag module and I would like it to allow an hashtag word to start with a number. Currently, the module doesn't allow an hashtag word to start with a number.
The code it uses is the following.
$pattern = "/[\s>]+?#([[:alpha:]][[:alnum:]_]*[^<\s[:punct:]])/iu";

I would like it to allow alpha-number or number-aplha.


texts:
Hi All I have I issue for my content type
like

I have content type  of property    user can add property fields
this is  ok
My problem is  i have to add  static form every time . i want it
default of every content  type is it possible please give me
suggestion for this


texts: How do I actually change the site name on a localized site?

texts:
Even after changing the settings in /admin/config/system/site-information, the page title still contains "Drupal".

All external examinations of the site configuration (config table and exported files) show the new name.

I examined the function template_preprocess_html() in theme.inc (where the configuration value is supposed to be loaded and entered in the theme variables), and inserted the following var_dumps:

var_dump(\Drupal::config('system.site')->getRawData()['name']);
var_dump(\Drupal::config('system.site')->get('name'));
var_dump(\Drupal::config('system.site')->getOriginal('name'));

The resulting output is string(12) "My Site Name" string(6) "Drupal" string(6) "Drupal".

The configuration value isn't overridden anywhere in the site's settings files either. All caches are cleared.

Why is ->get('name') returning the wrong value even though ->getRawData() contains the correct one?

Edit: I should probably add that this is a site with a non-English default language. That seems to be the cause of nearly all the configuration-related core bugs. However, the langcode of the sytem.site configuration entity is correctly set.

Edit: More digging reveals that the language module is indeed responsible for overriding the configured name with the default name.

Edit3: There doesn't appear to be a way to set the localized site information without editing the configuration externally. I exported it, deleted the file language/de/system.site.yml and re-imported, which fixed it. (In the production site, importing didn't remove the deleted configuration entity; I had to delete the language.de/system.site record from the config table directly.)


texts: Am trying to create xml feed through views feed generation to get the node content values. I have mapped the fields and i am getting the feed also, but a single space while generating feed in front of the xml feed. i.e before tag "<?xml" I am getting one single space. So that my feed page it's showing white space in Firefox and I can find the space in chrome browser. Is there config issue will be there or any thing else? Can anyone give me solution for this?


texts:
I have a website where three languages are present. I am requesting nodes through the Services API endpoint and that part is working well.

When requesting a node via JSON, how does the API let me know the requested node ID is associated to translated nodes?

I know the translated nodes do contain a "tnid" record of the original node, but the original node doesn't have anything to indicate that there are translated nodes.


texts: Search option just as that provided in drupal.org

texts:
can you please tell me which module to use to provide search options just as the search provided in https://drupal.org/download

Thanks


texts: Drag and drop no longer working on my drupal 7 site after workbench acess install

texts:
When I enable the workbench access module, all drag and drop reordering is broken. It doesn't work under blocks or under the menus. This doesn't happen on my local computer.

The working bench acess module I have is 7.x-1.2 under drupal 7.28


texts: Cant figure out what's wrong with my image style generation code

texts:
The code outputs and does exactly what I intend it to do, but it throws the following notices:

  Warning: Illegal string offset 'effects' in
  image_style_create_derivative() (line 928 of
  /var/www/html/modules/image/image.module). Warning: Invalid argument
  supplied for foreach() in image_style_create_derivative() (line 928 of
  /var/www/html/modules/image/image.module).

The code I am using is so:

(Builds the actual image style from base uri if the file doesn't currently exist)

/**
 * Check for and generate image derivatives if none exist.
 *
 * @param string $style
 *   Image style to check.
 * @param string $uri
 *   URI of the base image.
 *
 * @return false|string
 *   Returns uri for the image that should now exist.
 */
function _srv_image_derivitives($style, $uri) {

  // So I have something to return.
  $final_uri = image_style_path($style, $uri);

  // Gets the absolute file name to the file to check for.
  $filename = drupal_realpath($final_uri);

  // If it's not there, make it there.
  if (!file_exists($filename)) {
    $style_load = image_style_load($style);

    if (count($style_load)) {
      image_style_create_derivative(
        $style,
        $uri,
        image_style_path(
          $style,
          $uri
        )
      );
    }
  }
  return $final_uri;
}

(Builds an array of images that will be converted to a json array for an rest post)

/**
 * Build derivatives array from base image uri.
 *
 * @param string $image_uri
 *   The base image to construct.
 *
 * @return array
 *   Array of image derivatives.
 */
function _srv_build_derivative_array($image_uri) {
  // Set up the image styles to be used.
  $image_styles = array(
    'carousel',
    'rotator',
    'leadlandscape',
    'focus',
    'linkthumbnail',
    'topstorythumbnail',
    'topnavthumbnail',
    'lateststoriesthumbnail',
    'headline',
    'subcategorylead',
    'opinionlead',
    'entertainmentlead',
    'entertainmentlatestthumbnail',
    'gallerylandscape',
    'gallerythumbnail',
    'reporterstory',
    'galleryportrait',
  );
  $images_array = array();

  foreach ($image_styles as $key_one => $style) {
    $image_style_uri = _srv_image_derivitives($style, $image_uri);

    // EFS path instead of public:// uri.
    $images_array[$style] = str_replace("public://", "/data/sites_default_files/", $image_style_uri);
  }
  return $images_array;
}


texts: Multi-Valued Field Collection Token Issue

texts:
I have a field collection field in a content type that takes multiple values.  I am trying to access single values of that field to use via a token.  The issue is the following:

(the field is called field_slides)

The token [node:field_slides] returns to me the html for all of the values of the field.
The token [node:field_slides:1] etc does not work.
The token [node:field-slides:1] does work but it resolves to the string "slides 2"
I can get at the internal values of the fields as follows:
[node:field-slides:1:title] gives me the value of the title field within the individual entry.

I would like to simply access the html for the individual value which should be accessible through either:
[node:field_slides:1]
or
[node:field-slides:1]
but it isn't.

Any ideas?


texts: I have three blocks A, B and C and I need to embed the blocks A and B into the template of a block C.  Is it possible?


texts: Can we use panels for header and footer?

texts:
I have a few different top menus which I want to display in certain contexts, and ideally this should go in the header region. However, I have found that Panels can only take over the content region, and the right and left sidebars.

Is there a way to make panels for the header (and footer) regions?

EDIT:
I am using the Bootstrap theme, so I'm not sure if this plays well with the Panels Everywhere theme.


texts: Basic authentication for external application making requests to Drupal instance

texts:
I have a external application that makes requests for content in my Drupal 8 instance. What I want to do is to make sure Drupal is only talking go my external application to stop traffic being spoofed.

I want to create a username and password for this application and have it add the credentials to the request like this https://username:password@test.local.com

How would I use the basic authentication module to check is the request has the username and password added and then authenticate the request and then send the response as needed?


texts: How to specify the file path for the private file system?

texts:
Environment: Shared hosting, Apache.
Home directory: /home/someuser
Website at: /home/someuser/public_html/stuff
I've spent 2 days trying to get this to work, and realise that as soon as I'm answered it will be blindingly obvious, but I'm failing miserably right now.
I have created a directory in my public_html directory called private_files with a sub-directory called stuff. Both have access rights 755.
I have edited settings.php to include the line:
# $settings['file_private_path']
= '/home/someuser/public_html/private_files/stuff';

I have cleared all caches.
The file system configuration page shows:

Private file system path
Not set

What stunningly stupid mistake am I making? Why is what I'm doing wrong?


texts: User being logged out of drupal when using form redirect

texts:
Looking at my logs I have an issue. I have not been able to recreate it myself.

I have a form which an anonymous user fills out. This form takes an email address. When submitting the form I take that email address and either log the user in or create an account and log the user in.

This code is working fine. As I have several watchdog() calls going in as the user who has been logged in.

The code then creates an order in Drupal commerce (with the user account above). I have a valid orderid created with the above user.

I then have:

watchdog('MyMod', t("Logged in as user));
drupal_goto('checkout/' . $orderid . '/review');

The watchdog() goes in as the user. When I hit checkout/????/review I then get an access denied for an Anonymous user.

This is only happening some of the time. As I said I have not been able to reproduce. What could be causing the drupal_goto() to log my user out.

Update

I now use

watchdog('MyMod', t("Insert in ref table complete"));
$formstate['redirect'] = 'checkout/' . $orderid . '/review';

To redirect my user however I am still getting the same issue.

Update 2

With some code.

Log out user

function _mymod_logout_user() {
  global $user;
  if ($user->uid > 1) {
    module_invoke_all('user_logout', $user);
    session_destroy();
  }
}

Create User

function _mymod_create_user($mail) {
  global $user;
  _mymod_logout_user();
  if ($user->uid != 0) {
    return $user;
  }

  $account = user_load_by_mail($mail);

  if ($account == FALSE) {

    $password = 'random12!££SsjsjaJAAJA3'; //made up

    //set up the user fields
    $fields = array(
      'name' => $mail,
      'mail' => $mail,
      'pass' => $password,
      'status' => 1,
      'init' => 'email address',
      'roles' => array(
        DRUPAL_AUTHENTICATED_RID => 'authenticated user',
      ),
    );

    $account = user_save('', $fields);
  }

  // If the user is 1 then we want to return false as they will be logged in as admin
  if ($account->uid == 1) {
    return FALSE;
  }

  $form_state = array();
  $form_state['uid'] = $account->uid;
  user_login_submit(array(), $form_state);

  return $account;
}

Create Order

function _mymod_create_order($sku, $mail) {
  global $user;
  $user = _mymod_create_user($mail);

  // User is trying to create an account under user 1 so return nothing.
  // can only do this if logged in a user 1 not anon
  if ($user == FALSE) {
    return;
  }
  $uid = $user->uid;

  $order = commerce_order_new($uid, 'checkout_review');
  $product = commerce_product_load_by_sku($sku);
  $line_item = commerce_product_line_item_new($product, 1, $order->order_id, array());
  commerce_line_item_save($line_item);

  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper->commerce_line_items[] = $line_item;
  commerce_order_save($order);
  return $order->order_id;
}

Insert into custom table

function _mymod_insert_ref_table($orderid, $ref) {
  db_insert('mymod_reference_table')
    ->fields(array(
      'orderid' => $orderid,
      'ref' => $ref,
    ))
    ->execute();
}

Form submit function

function mymod_form_submit($form, &$formstate) {
  global $conf;

  $sku = //Code that generates a SKU;

  $orderid = _mymod_create_order($sku, $form['email']['#value']); //email has all ready been validated by drupal

  $ref = // Call to WS that returns a reference number
  _mymod_insert_ref_table($orderid, $ref);
  watchdog('My Mod', t("Insert in ref table complete")); // This watchdog message goes in as the logged in user!
  $formstate['redirect'] = 'checkout/' . $orderid . '/review';  // When I reach this page I am logged out sometimes...

}


texts: How to override prepareTranslation method in Drupal\content_translation\Controller in drupal 8?

texts: I want to override prepareTranslation method using my custom module in drupal 8. You can find this function here(Drupal\core\modules\content_translation\src\Controller\ContentTranslationController.php).


texts: How can I translate or add words that seems not to be part of core strings?

texts:
I currently use formatPlural() to translate comment (not comments) and return its value to the Twig template.

\Drupal::translation()->formatPlural('', '1 comment', '@count comments');

Is there any way to use code similar to the following one in a Twig template to translate this word?

{{ 'comment'|trans }}
{{ 'comment'|t }}
{% trans %}comment{% endtrans %}


texts: Is accessing the current node from multiple block plugins on a single page costly from a performance perspective?

texts:
I use a combination of Block plugins and panels to populate the layouts of the display modes of various content types.

Here's an example:

class MyBlockPlugin extends BlockBase
{
    /**
     * {@inheritdoc}
     */

    public function build()
    {
        $node = \Drupal::routeMatch()->getParameter('node');
        $profile_pic = ImageStyle::load('350x300')->buildUrl($node->field_image->entity->getFileUri());
        return [
            '#theme' => 'mytwigtheme',
            '#name' => $node->title->value,
            '#headshot' => $profile_pic
        ];
    }
}

It certainly works but I'm wondering if this is a bad path to travel because I'll have multiple block plugins loading and accessing the same node. I suppose I could access the node with a preprocess block hook but I'm assuming that will load for every block as well.

If the performance cost is trivial then I'm not too worried about redundancy. Is my method okay? If not, what would be a better way for a block plugin to access the data of the current node it appears on?

Update:
Just another thought. Is me using a twig template making this a non issue as long as it's been loaded before?


texts:
I am writing a module that allows users to put comment on each paragraph.
So in my module I have added a new field to comment table called "paragraph_id" and I have also added a new field to comment form that say:

 Which paragraph do you want to put comment on?

After each paragraph I have added a link saying:

  Put comment on paragraph 1 (2,3, ...., the number changed based on the number of the paragraph.

in order to this, I have written the following in node.tpl.php:

        for ($i=1;$i<$number;$i++) {

        print render($paragraphs[$i]);
       ?>

      Put comment for Paragraph <?php echo $i?>

    <?php

I want to do one the following options:

1) Eliminate the new field which asks for the number of the paragraph from comment form, and do something that when a user for example clicks on a link like:

   Put comment on paragraph 1

, the number "1" automatically got save in comment table in "paragraph_id" field.

2) Or  keep the field that asks for paragraph number in comment form and when user clicks on a link like

 Put Comment on Paragraph 1

while he is getting directed to the comment form, the value of that field (paragraph_number in comment form) sets to 1.

How can I do it?


texts: How to add a class to the site logo of the system branding block

texts:
I'd like to add a class of 'svg' to my site_logo img itself using template preprocess. Here's what I have written:

 function mythemename_preprocess_block__system_branding_block(&$variables) {
      $variables['elements']['content']['site_logo']['attributes']['class'][] = 'svg';
      kint($variables);
 }

The kint($variables) readout for where I'd expect my class to be shows DEPTH TOO GREAT. See:

I've seen some documentation saying it has to do with Kint's depth limit, which doesn't seem right as the preprocess isn't very complex. It suggested using +Kint::dump();, which I tried and can't seem to get working. +Kint::dump($variables) didn't work.


texts: I want to modify the menu.inc file that is in the Drupal "includes" folder, but I want to create an overriding file for it, so that we can easily package only our custom theme.


texts: Upgrading/downgrading recurring digital service plans with Commerce License

texts:
I've set a stock Drupal 7 website using the minimal installation profile and configured the Commerce License Billing module to take care of monthly, quarterly and yearly recurring subscription plans. However, it is quite confusing how to make possible for the end-users to upgrade or downgrade to/from other plans.

All subscription plans should be prepaid and be upgradable and downgradable at any moment end-user wants, so should also be automatically calculated on pro-rated basis. Trying many different settings per https://www.drupal.org/node/2127603 doesn't help at all:

editing currently recurring orders won't work as every new edit is saved as just a revision and doesn't effect the amount charged next time - it doesn't change.
adding a new line item (upgraded or downgraded plan) to the last order (with Recurring: Open status) doesn't save.

Is it possible at all to setup a Drupal Commerce site which would allow upgrade and downgrade recurring plans using already existing contributed modules?

Or additional custom coding is required? And if so then why the https://www.drupal.org/node/2127603 page lists different billing types? Are they indeed available without additional custom solutions?


texts: How to call custom javascript function defined in js file from .module file

texts:
I have some custom menu defined for which in the page callback function I want to execute some javascript function defined in some js file which is included in .info file.

The alert and console.log works as file is included on the page and loading successfully in browser, but custom js function not working. It says function is not defined.

.info file:

scripts[] = js/code_init.js

Here is my code in .module file:

function mymod_process_file(){

     $count = 2;
     for($i = 1; $i <= $count; $i++) {
     $file_path = "/abcd.html";

     echo "counter:$i";
     echo "<script language='javascript' type='text/javascript'>";
     echo "myFunction('".$file_path."', 'index_".$i."');";
     echo "</script>";
     }
     return 1;
}


texts: Drupal 7 Most Popular Tags in a list as a block: How?

texts:
I have found Tagadelic works very well out of the box and is, to my hours of research and knowledge, the only plug & play feature for a tag cloud available for Drupal 7.

This is the only problem I've run into--I want the functionality of Tagadelic but do not need it in the "cloud" format. I need my tag cloud to be in a list from most popular to least popular and no size variation. For example:

Item x
Item h
Item j
Item o
Item 4

Obviously the most popular item being 'Item x' and the least popular item being 'Item 4' How can Tagadelic be modified to this as I know it will require more than a CSS fix? Or is there a better option than Tagadelic?


texts: How to add contact us form in to front-page?

texts:
I need to add contact form in the front page but I don't know how. there are some modules like Contact Form On Node that inserts this form in the node page but I only want it to be in the front page. how do I can do this ?

thanks


texts: How do I programmatically enable a view mode?

texts:
Let's say I have created a new view mode with DS. How can I activate it programmatically?

I want to achieve this because I'm doing an export with features but, despite the Features module exports DS settings and layouts, it does not automagically activate them. I'm planning to active this new display inside an install hook or something like that.

I looked in the tables schema, but I could not tell what activates a view mode.


texts:
I´m not able to theme a views block. I have found a lot of tutorials on how to rename the twig file, but i´m sure that i´m doing anything wrong with filename.

I use the views-view.html.twig and i have copied it into my theme folder. The machine name of the views block is: views_block__kurstermine_block_1.

I have tried several block names, but no one works. Please can somebody explain me?

views-view--views_block__kurstermine_block_1.html.twig = false
views-view--views_block--kurstermine-block-1.html.twig = false

Thank you!


texts: Using function of views_embed_view may caused high CPU loading

texts:
I found that a page in my Drupal site is causing high CPU/memory loading, I tried to remove each item(e.g. block, custom PHP code and so on) on this page. Finally, I found that if I remove the code below will drop down the CPU/memory usage from 90% to 10%.

print views_embed_view('flag_compare', 'block_1');

Could someone suggest another function to embed view?


texts: Dependency injection not working custom form

texts:
I have a custom module with a form class, where I am trying to inject a custom service to use within it's submit method:

namespace Drupal\my_module\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\my_module\CustomManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

class CustomForm extends FormBase{

  private $custom_manager;

  function __construct(CustomManager $custom_manager) {
    $this->custom_manager = $custom_manager;
  }

  public static function create(ContainerInterface $container) {
    return new static(
    // Load the service required to construct this class.
      $container->get('my_module.manager')
    );
  }

  .....

  public function submitForm(array &$form, FormStateInterface $form_state) {
      // Test service.
      $this->custom_manager->test();
  }

}

When I submit the form, I get the following error:

Fatal error: Call to a member function test() on null

It seems like my custom service hasn't been instantiated as expected, since the $custom_manager property is null.

Strange thing is when I debug the constructor, the service IS being instantiated properly.

Has anyone had this issue before? I can instantiate the service via the global Drupal class, but apparently doing the dependency injection is best practice.

Thanks in advance!


texts:
I make use of the view: "taxonomy term". Is there an easy way to also show the children of a term, next to the nodes beloging to this term?

Example:

Cars
- Volvo
--- Family_cars
--- Sports_cars
- Honda
--- Parts
--- ...
Trucks
- ...

When you see the "cars" page I want to show all articles about cars (but not about Volvo, Honda, ...) AND I want to show the children (Volvo, Honda, ...) When you click one of these I want to show all the articles belonging with them, again with their children.


texts: How to make disqus load avatar picture instead of user picture?

texts:
In user profiles I created a field called Avatar with a machine name of field_avatar.

I was wondering if I could make Disqus load the Avatar picture instead of the default Drupal user picture.

Here is the default Disqus code

        // Load the user's avatar.
    $user_picture_default = variable_get('user_picture_default', '');
    if (isset($account->picture) && !empty($account->picture) && is_numeric($account->picture) && $file = file_load($account->picture)) {
      $data['avatar'] = !empty($file->uri) ? $file->uri : NULL;
    }
    elseif (!empty($user_picture_default)) {
      $data['avatar'] = variable_get('user_picture_default', '');
    }
    if (isset($data['avatar'])) {
      $data['avatar'] = file_create_url($data['avatar']);
    }
  }
  drupal_alter('disqus_user_data', $data);

  return $data;
}


texts: How to change uploaded file name after save node?

texts:
Hello and thanks for looking my question.

On Drupal 7 I use this hook hook_file_presave() for change file name.

function mymodule_file_presave($file) {
  $parts = pathinfo($file->filename);
  $file->filename = $file->uid . $file->timestamp . '.' . $parts['extension'];
}

But how to do it on Drupal 8.1.x? Programmatically or module ways or something else?


texts: Trying to create a static page for my module using page callback in hook_menu

texts:
I’m taking first steps in building a module for Drupal 7 and am trying to create a static page within hook_menu function. In the $items array, for ‘page callback' I create an very simple function named ‘semi_static_page’. This simple function returns some html. the code is below.

$items['admin/config/media/tsoundcloud/config/soundcloud_static'] =             array(
    'title' => t('Semi Static Page'),
    'description' => 'Temp page to show data',
    'page callback' => 'semi_static_page',
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
    );

function semi_static_page(){
  $output = 'this is some output, etc…….’;
  return $output;
}

But this page generate the following error.

Fatal error: Unsupported operand types in /Users/tomcarden/Sites/sweetteas/includes/form.inc on line 1079

How can this be resolved? Ultimately I want to load an .inc in the semi_static_page function.

thanks in advance!


texts:
Recently my drupal site is hacked. When i see website log from drupal admin panel someone trying to inject code from url. I searched my website(drupal) directory lots of code in page appended and new files are created.

My question is that

Is this possible to inject code from url
If use how to protect them in drupal

log image


texts: How create a file type field in custom entity programmatically?

texts:
This is how i create my field in my Entity content :

  $fields['fid'] = BaseFieldDefinition::create('file')
      ->setLabel(t('Photo'))
      ->setRequired(false)
      ->setDescription(t('Product image'))
      ->setSettings(array(
          'upload_location' => 'public://produits/',
          'upload_validators' => array(
              'file_validate_extensions' => array('png jpg jpeg'),
          ),
      ))
      ->setDisplayOptions('view', array(
          'label' => 'above',
          'type' => 'file',
          'weight' => -3,
      ))
      ->setDisplayOptions('form', array(
          'type' => 'file',
          'settings' => array(
              'upload_location' => 'public://produits/',
              'upload_validators' => array(
                  'file_validate_extensions' => array('png jpg jpeg'),
              ),
          ),
          'weight' => -1,
      ))

      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

The field is create in my form but when i try to upload a file :

I got this error :

  Only '.txt' extension is authorized

Edit 1 :

In fact my settings are never read, after upload a .txt for test, the directory is wrong.

Any idea about this ?


texts: Webform email component created programmatically

texts:
I am trying to build an email confirmation utility into a web application. For some other project I might just use jQuery to insert a new text field beneath my email field and compare their input as soon as the user finishes typing into the created textfield.

The problem is the email authentication will fail if a user does not have javascript enabled on his/her browser.

To overcome this problem, I want to use code to programmatically create and insert a second textfield immediately after the actual email field and compare their input when the user submits.

What I don't know is what webform hook(s) I can use to create an email component.

Can anyone help with some information and/or code samples, please?


texts: Set amount of fields on an existing content type

texts:
One of our website requirements is to have a content type that lets you decide on the total amount of form fields on the fly.

For example, if I specify a number 10, then it ought to generate the form fields consecutively; the text area and the checkbox form fields are created 10 times.

Essentially, to break it programmatically, it will create:

for(i = 0; i < 10; i++) {
  echo "<input type = 'textarea'></input>";
  echo "<select><option>1</option><option>2</option></select>";
}

This is pretty straightforward if I was dabbling with simple PHP files, but with Drupal 7's fields it is posing a bigger challenge than what it ought to be. I have tried exploring modules that let you create content types on the fly and considered creating a custom content type programmatically which seems like another challenge altogether.

I am curious if anybody has an alternative for this, and has dabbled with this challenge before.


texts: Debugging a views_json view that shows data when logged in and is empty when logged out

texts:
OK, first the problem, then the setup:

The Problem

I have a taxonomy view that returns json containing data about nodes that are associated with a taxonomy term.  When I am logged in with any role, the view shows data.  When I am not logged in the json is empty.

The Setup

I have a taxonomy view that returns json containing data about nodes that are associated with a taxonomy term.  The paths are json_file/%/en and json_file/%/ja depending on the language the query is made in.  There are then filters checking content type, language, and the state of a couple of file upload fields as well as a filter checking that the content is published.  Access control is set to Role with all roles including anonymous user checked.  Contextual filters are Content: Has taxonomy ID (with depth) and Content: Has Taxonomy term ID depth modifier.

In practice the url ends up looking like /json_file/climate/en because in MYMODULE_views_pre_view I look up the tid based on the value in the url and replace the argument.  I have confirmed that it is properly getting the tid.

So between the Access settings including anonymous users, the filter not containing anything to prevent anonymous users from seeing the data, and there being nothing related to the issue in the contextual filters, I'm wondering what else I can do to debug this? What might cause a view to have no result when a user is not logged in?

I've tried:

I've tried changing the Access control to None and clearing cache.
I've removed the content published filter and cleared the cache.
I've removed all caching that I could find from the view and cleared the cache.


texts:
I've looked around but didn't find the right solution. In D7.5x I would like to create different view modes (of Full Content) per role. I am using Display Suite.

The situation should be like this: I have teaser view mode, Full content (limited) view mode, Full Content (extra) view mode. Is there any quick solution, to let users with role A after clicking onto link in teaser view mode get to see Full content (limited) and users with role B get Full content (extra)?

tnx


texts: Change Input Field Value using Hook Form Alter (User Login Block)

texts: How would I go about changing the input field value from e.g. 15 to 10 in the default User Login Block for Username and Password fields, using Hook Form Alter?


texts: What could cause the site to suddenly start dying with the "Call to undefined function entity_get_info()" error?

texts:
So I was working away at trying to solve the problem I asked about in How can I combine the fields of two field collections in my theme? when suddenly Drupal died with this error message:

  Fatal error: Call to undefined function entity_get_info() in /path/to/drupal/sites/all/modules/entity/includes/entity.inc on line 57

This is the call stack.

Now since it seems to die when working with the field collection module, and I was working with that field, it is obvious that something I did caused the entire site to crash, but how, and how can I recover from it?  I can't clear cache to try to see if that fixes anything because drush throws the same error and I can't access the cache clear on the site itself obviously.

What I was doing

I was working on the theme_preprocess_field() function and had something like this:

<?php
function enviroscope_preprocess_field(&$variables) {
    $roles = array();
    if ($variables['field_name_css'] == 'field-doc-staff-contrib-fc') {
        foreach ($variables['items'] as $item) {
            $role = array_values($item['entity']['field_collection_item'])[0]['field_fc_doc_iges_role'][0]['#markup'];
            $user = array_values($item['entity']['field_collection_item'])[0]['field_fc_doc_iges_user'];
            $toreplace = $user['#object']->field_fc_doc_iges_user['und'][0]['entity']->name;
            $replacewith = $user['#object']->field_fc_doc_iges_user['und'][0]['entity']->field_user_family_name['en'][0]['#safe_value']
            $roles[$role][] = $item;
        }
    }
    kpr($roles);
}

I started adding some scaffolding for the next step, which was to be examining the field-doc-other-contrib-fc field collection field.

I meant to modify the code after kpr($roles); to read as follows:

    kpr($roles);
    variable_set('roles_to_pass', $roles);
} else if ($variables['field_name_css'] == 'field-doc-other-contrib-fc') {
    $roles = variable_get('roles_to_pass', array());
    // sort and mix these together
    variable_del('roles_to_pass');
}

My best guess about what possibly could have happened is that I accidentally wrote else if ($variables['field_name_css'] = 'field-doc-other-contrib-fc') { (note the = instead of the ==) which would have reset the field_name_css on every field except the first field collection field I was working on.  Would this explain the entire site going down in the way it has?  How can I recover from it?

In the morning if there is no answer I'll try deleting all rows from the various cache_* tables directly in the database, but for now I need to hit the hay.

Update

Clearing out the cache tables and commenting out my entire template.php had no effect.  Is my entire install hosed?


texts: How do I alter the route defined by another module?

texts:
In other words, what is the Drupal 8 equivalent of hook_menu_alter()?

Drupal 8 still uses hook_menu(), but for what I can see, the information returned by the hook is different from what the hook returned in Drupal 7. For example, the definition given in user_menu() for user is the following.

  $items['user'] = array(
    'title' => 'User account',
    'title callback' => 'user_menu_title',
    'weight' => -10,
    'route_name' => 'user_page',
    'menu_name' => 'account',
  );

The route_name property links to an entry in the user.routing.yml file.

user_page:
  pattern: '/user'
  defaults:
    _content: '\Drupal\user\Controller\UserController::userPage'
  requirements:
    _access: 'TRUE'

This is different from what done with Symphony, and it confuses me about how a module can alter the route defined from another user.

The only function that is still invoking hook_menu_alter() is menu_router_build(), but that function still contains code that needs to be updated, since it is still using the now deprecated drupal_alter().

  // Alter the menu as defined in modules, keys are like user/%user.
  drupal_alter('menu', $callbacks);
  foreach ($callbacks as $path => $router_item) {
    // If the menu item is a default local task and incorrectly references a
    // route, remove it.
    // @todo This may be removed later depending on the outcome of
    // http://drupal.org/node/1889790
    if (isset($router_item['type']) && $router_item['type'] == MENU_DEFAULT_LOCAL_TASK) {
      unset($callbacks[$path]['route_name']);
    }
    // If the menu item references a route, normalize the route information
    // into the old structure. Note that routes are keyed by name, not path,
    // so the path of the route takes precedence.
    if (isset($router_item['route_name'])) {
      $router_item['page callback'] = 'USES_ROUTE';
      $router_item['access callback'] = TRUE;
      $new_path = _menu_router_translate_route($router_item['route_name']);

      unset($callbacks[$path]);
      $callbacks[$new_path] = $router_item;
    }
  }


texts:
I'm running an app where I am searching for every nodes of a given content type.

$nids = \Drupal::entityTypeManager()
  ->getListBuilder('node')
  ->getStorage()
  ->loadByProperties([
    'type' => 'courses',
    'status' => 1,
]);

I'm searching for a way to sort the results among a custom field of my nodes.

EDIT:
I do not understand what's going on.
Thanks to @4k4, I wrote this query:

$query = \Drupal::entityTypeManager()
    ->getListBuilder('node')
    ->getStorage()
    ->getQuery();
$query->condition('type', 'post');
$query->condition('status', 1);
$query->condition('field_category', $k);
$query->sort('field_ordering', 'ASC');

$nids = $query->execute();
$nids = Node::loadMultiple($nids);

A var_dump on $r[1] prints nothing. Same for $r[2]. But $results contains my results. What's going on ?
The sorting doesn't work by the way.


texts:
I'd like to create a page in D8 that allows my users to input some values. Once they've done that I'd like them to click a button that then creates two pie charts for them based on the values they input.

I see the Charts Module is not available for D8. Wondering if anyone here has suggestions for how best to accomplish this in D8 as of this writing?


texts: JSON URL access restriction within Drupal

texts:
I am using Drupanium in Drupal which generates JSON that can be assessed through a URL. The URL in turn is parsed by the app to show data.

Now the problem is that this URL can be publicly assessed by anyone too and anyone can see all the details. The app, on the other hand, shows the same data to the restrictive users.

My question is that how can I restrict anyone who opens the URL through a browser whilst also allowing the app to assess the data through the same URL?

The URL looks like this:-

http://site.com/section/allowed-users-in-the-list.json

Many Thanks.


texts: How to let users change their own profiles?

texts:
I have a site running Drupal 7.9 and users can register for their own account. Some of the fields they have to input can change over time (email adress and phone number(s)). Is there any way for me to make it so the user can change his/her own email address and phone numbers?

The only thing I could find in the documentation (and controlpanel) was how to enable users to change their own username, which gets me sort-of there but not quite.

Also, I tried googling this for the longest time but I couldn't find anything. Maybe my search terms were wrong?

Any help would be greatly appreciated!


texts:
I have created a View and added a filed Date. This Field have 4 type of Formatter

1) Date and Time
2) Time Ago
3) plain
4) Services Raw

If I select First it give HTML tags in output and if select 3rd or 4th it give output like these numbers "1439393400"

I need the simple date in output without any HTML tags. Please tell me how I can get rid of HTML tags if I select first option. If its not possible then how I can convert the output which I get from Plain Formatter so that I get simple date not these number.


texts: "You don't have permission to access / on this server"

texts:
I'm running my local development sites on a Windows machine with Uniserver. I have them all set up as vhosts and they work fine with Drupal 7. Recently I decided to install a vhost with Drupal 8, but when I go to the site I get the following error:

  403 Forbidden - You don't have permission to access / on this server

The error log for the site says:

  Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions

If I add Options +FollowSymLinks to the vhost's .htaccess file, it works fine.  How should I be doing this? I can't imagine Drupal 8 is supposed to have this done on every installation. For reference, I'm running the site on:

Apache 2.4.18
PHP 5.6.18
MySQL 5.6.28


texts: Is it possible to add an image watermark to an image with a condition based on field values of a node?

texts:
I am currently using imagecache_actions to add an image watermarks to the images I upload.

So far everything is working fine. What I am currently doing is just to simple add the site logo to the bottom right part of the images being uploaded.

Right now, what I am trying to figure out is is it possible for me to be able to add an image watermark to an image with a condition based on field values of a node?

For example, I have an image field in a node let's say it is the a person's image field and then an image watermark that says something like NEW if the node is 2 weeks old. Is that possible? Or maybe if I will add a field in the content type for like New Member - Yes or No, and if yes, the New image watermark will be added to the image of the member.


texts: How do I compile Mustache.php to use with the Template Field module?

texts:
The Template Field module requires the Mastache Template Rendering Library.

  The Mustache Template Rendering Library can be found here. It must be
  installed at libraries/mustache/Mustache.php.

However, the Mustache.php file is not provided, and I'm not sure why. There is some discussion about using the composure.php library to compile it. What I'm supposed to do?

The Template Field module is looking for a file called Mustache.php which doesn't exist in the git repo.

  /**
   * Verify anything before rendering
   * @param Template
   * @param array $data the data to render in the template
   * @return boolean
   */
  public function valid(Template $template, $data) {
    // Does the mustache library exist?
    if (file_exists(self::mustache_path())) {
      return TRUE;
    }

    watchdog('template_api', t('Mustache Library was not found'));
    return FALSE;
  }

  public static function mustache_path() {
    return libraries_get_path('mustache') . '/Mustache.php';
  }

There is a mention for using Composer but I'm not sure what that does. I have tried adding the Drush Composer extension to build a file but I don't understand how the Composer extension works.


texts: How to retrieve the link and description in a custom file field twig template

texts:
I have a field field_file. I've created a template field--field_file.html.twig.

How can I access the link, description (and attributes and icon ) separately in this file?

I have:

{% for item in items %}
  {{ item.content }}
{% endfor %}

which just spits out themed content.

I've debugged with dump() and there seems like the possibility of at least retrieving the 'description' somehow, but item.description does not work, for example.


texts: pass values from one form to the dropdown list in other form

texts:
I have a drop down list in one webform that takes it's values from the submission data of other webform. How can I pass the submission data on one form to the drop down list in the other ..

Many thanks.


texts: Module/Method to cleanup content of Drupal site?

texts:
I have been assigned with the task of maintaining a specific Drupal site. The problem is that the person who created the website did not actually think it through. No input filters to be heard of, no restriction for images' placement, plain HTML everywhere.

I'm now on the spot, since I've promised to tidy up the website, and I've just realized how much work will it require. There are articles that are copy+pasted from wikipedia (the WYSIWYG editor kept all the formatting), random websites or (even worse) from MS Word.

I understand that I will have to do some manual editing and check the articles one by one, but I was wondering if there is some kind of a method that someone may have used in a similar situation. Perhaps a module that will cleanup the html of the various nodes?

Note: The website is built in Drupal 6, but if you have suggestions for Drupal 7, I guess that I could upgrade.


texts: How do I control what to publish as Facebook Instant Articles?

texts:
I am using this Facebook Instant Articles module to integrate articles being published as Instant articles on Facebook. I have successfully tried to publish instant articles using the RSS Feed and Views modules.

When I look at the preview of the feed, the articles being added on the feed are all the articles recently published. This is not what I want. I checked the configuration, and I found out that I have to select each article.

Now, after doing this, I still can't filter out the articles which are selected to be published as instant articles. I tried adding a filter, but I can't add a Filter on my view. I have not yet added custom codes just via the administrative dashboard.

What I want is to freely filter out specific articles I want to publish as instant articles. In my case, the articles processed from the feed are the latest ones; if I edit an article to add it as instant article, it won't be shown.

Can someone help me here?


texts:
My bread crumb for some odd reason is showing home -> home ->.

I suspect it has something to do with the site structure but i'm not quite sure what that is.

Any ideas?


texts: How to output specific php depending on value of content type radio

texts:
In my 'Basic page' content type I've added a yes/no radio field. Currently that is outputting as the value chosen. If yes is chosen I want to output a specific button, if no was chosen I don't want to output anything. How do I go about overriding the basic page template to achieve this?

--EDIT--
I don't want the radio option showing for the site visitor, only for the content editor. I want either the button or nothing showing to the site visitor.


texts: How to allow comment author to reply to comments on his posts

texts:
The answer to "How to restrict node authors from commenting on their own nodes?" includes a rule that unpublishes comments made by an author on his own posts. The rule works and is reproduced below.

{ "rules_unpublish_selected_comments" : {
    "LABEL" : "Unpublish selected comments",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "comment" ],
    "ON" : { "comment_insert" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "comment:node:author" ], "value" : [ "comment:author" ] } }
],
    "DO" : [ { "data_set" : { "data" : [ "comment:status" ], "value" : "0" } } ]
  }
}

To refine it further, how would you modify the rule so that the comment author could reply to comments made by others on his own post or node?


texts:
I need to find out what credit card type was used when someone purchased something from my website.

Is it possible to find this out? I was looking through the database tables and couldn't find anything in there. I also looked in the orders payment tab and still couldn't find anything.

Thanks


texts: Serving Drupal from within a sub-directory of my web root

texts:
I need my Drupal 8 website to be served from within a subdirectory of my NGINX_SERVER_ROOT but is doesn't work.

Drupal should be reached at mydomain.com/drupal.

My NGINX_SERVER_ROOT is /var/www/html/web.

When the source code is in /var/www/html/web it works fine. But when moved to /var/www/html/web/drupal and I try to reach mydomain.com/drupal, it doesn't work.

I have edited the .htaccess file within the drupal subfolder and set RewriteBase /drupal as explained in the file itself.

Here is the log when I try to access my Drupal installation.

nginx_1    | 2018/10/09 12:58:38 [error] 42#42: *5 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.160.4, server: default, request: "GET /drupal HTTP/1.1", upstream: "fastcgi://192.168.160.5:9000", host: "d8site.local:8000"
nginx_1    | 192.168.160.4 - - [09/Oct/2018:12:58:38 +0000] "GET /drupal HTTP/1.1" 404 47 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
nginx_1    | 192.168.160.4 - - [09/Oct/2018:12:58:38 +0000] "GET /favicon.ico HTTP/1.1" 200 43 "http://d8site.local:8000/drupal" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"

Could someone point me in the right direction?


texts: How can I get file field url in drupal 7 from views of its content type?

texts:
It has been a few days I'm trying to get the uploaded file urls in drupal7 (using default file filed in drupal content type) from a view. I must get this url in page which a view is embedded inside it, this view shows 10 items of its content type per page, how can I get the url of filefield?

should I use preprocess function or any thing else?

I have tried many ways suggested in many websites but I have failed. is there any straight forward solution?


texts: How do I know if I installed latest version?

texts:
I am trying to create a cron script which uses Drush, and that does the following (using pseudo-code).

if([My Drupal core version] < [The last core version]) {
    [Backup DB]
    [Put the site into maintenance mode]
    [Upgrade core]
    [Remove the site from maintenance mode]
}

I don't know, how to implement [My Drupal core version] < [The last core version].

How do I check if the site is using the latest version of Drupal?


texts:
I have a very weird problem, my custom forms submition doesn't work unless devel module is active.
any ideas how to solve this problem?

function forexCompare_form_submit($form,&$form_state){

$array = unserialize(variable_get('forexCompare_company1',""));

$array[] = t($_POST['forexCompare_company1']);
variable_set('forexCompare_company1',serialize($array));
//drupal_set_message(print_r($form_state)." k".$_POST['forexCompare_company1']);
}

function forexCompare_form($form,&$form_state){
return array(
            'forexCompare_company1' => array(
                '#type' => 'select',
                '#title' => 'Company #1',
                '#options' => getCompanies()
            ),
            'forexCompare_company2' => array(
                '#type' => 'select',
                '#title' => 'Company #2',
                '#options' => get_stored_comp()
            ),
            'submit' => array(
                '#type' => 'submit',
                '#value' => 'Save',
            ),
            '#submit' => array(
               'forexCompare_form_submit'
            )

);
}

i have notice that when i return the drupal_get_form() on the page callback , but when i pass it as variable in theme function doesnt work

function userOptions_theme(){
global $user;
$user_loaded = user_load($user->uid);
return array(
  'settings_user_transfer'=>array(
      'template' => 'setting',
      'variables' => array('money' => $user_loaded,'form' => drupal_get_form('userOptions_form'))
  )
);
}


texts: I have a LDAP server and my website runs on drupal 6. So i want users from LDAP to access my website using their login details. Which module is preferable for this. i want users to be created on drupal and authentication to happen with LDAP server.


texts: How can I create nodes in a installation profile? Can this be done in the .info file, or does it have to be done in the .install file?


texts: Display of referenced entity fields with or without link to entity, depending on type of referenced entity

texts:
I need to display a publication of a group.
The authors of a publication can be members of the group or not.

In the edit page of the publication the authors can be added through a referenced entity field. References can be made to node of type "member" or to node of type "external author".

I would like to output the result as:

Title of publication
Author 1 (link to the member's personal page), Author 2 (no link to other page), Author 3 (link to personal page), Author 4 (link to personal page)

So,

if referenced entity is of type member -> author

if referenced entity is of type external author -> author

like:

author 1 author 2 author 3 author 4

The twig template contains the code:

{% for item in items %}
  <span{{ item.attributes.addClass('field__item') }}>{{ item.content }}</span>
{% endfor %}

Is it possible to adjust the code to display the publication the way I would like.

Thanks in advance


texts: Replacing a specific content creation with the newest version

texts:
I'm creating a website that tracks users weight. A user can create content to enter their weight and I have a view that displays all entries of a users weight however I want it so that if a user makes two entries on a single day that only the most recent from that day is shown and all the rest are not.

I have tried limiting the date but no success.


texts:
I have a content type that allows users to make their own tags, for me to be able to properly search through these tags I need them to be in a specific format.

Rather than burden users with my strict formatting guideline I would like to just alter the input to my format before creating the tag. Is such a thing possible?


texts: I've seen this question posted many places, but no answers - or relevant answer. i.e. how to get term object or ID from path or alias e.g. /cat/subcat or /taxonomy/term/6??


texts: Get data from one editor field and pass that into another editor field

texts:
I have no idea if this is even possible, but I figured I'd ask anyway.
I'm working with a site that is on Drupal 8, and long story short, we don't have access to extending nor updating much so any custom layouts that we would need or want to manipulate is all done via JS and CSS on the front end.
With that being said, I was wondering if it's possible to get data from one editor field and pass that into another. So for this example, I would try to take the content that was in a "title" field and then pass that into some JS code that is in another one. Something like this:

Which would then output something like this:

<script>
jQuery(document).ready(function($) {
      $('h2:contains("Title for thing...")').attr("id", "enroll");
});
</script>

Again, I have no clue if something like this is remotely possible. I new to Drupal but my hands are kinda tied when it comes to adding new stuff to the editor (has to get approved, etc, etc) and so I'm looking for ways that I can try to "future proof" anything that I can make but then if someone edits the content it doesn't run the risk of breaking the layout. I know, not ideal by any means, but I'm just trying out some ideas if possible.


texts: I've got a filter criteria saying field xyz = NO. Old nodes meeting the criteria above do not get picked up by the filter. When I edit the node, and resave it, only then they appear in the view. Is there a reason for this?


texts:
Is there a way to add class to any element through CKEditor?

Here is an example: I create a list with CKEditor and I want to add a class to the ul tag. Or maybe on one of the li.

Everything without opening the source of course.

Is there any way to achieve that? (with CKEditor or with another WYSIWYG)


texts:
I have to say I feel embarrassed but after several hours of unsuccessful trials and fruitless research I am resigned to ask for help to the community.

6 months ago I have changed the Read More text link to More information. Now I am asked to roll back to Read More and I can't find out how I made it the first time. I am sure I did not override any function in the theme and almost sure I did write any PHP code.

I believe I have done something with the internationalization module because I have now both strings Read more and More information in the buit-in interface textgroup.

So how can I map the Read more link text to a given entry in the built-in interface?

Thank you!


texts: I'm making an AJAX call in drupal 7 via the standard AJAX Framework. My  problem is that when a status message is set by the AJAX callback, it is simply lost (or displayed at the next reload of the page). How can I display the status messages right after the AJAX callback has finished running, without reloading the page? Is there a module for that?


texts: Problem changing language - Redirection to installation

texts:
By browsing my website in Drupal, I can browse perfectly through all the sections.
The website has 3 languages.
For Spanish, I can navigate well.
For English, I can navigate well

But any page I try to access in Portuguese, redirects me to "core / install.php"

I have cleaned cache, I have reviewed everything, and it only happens to me when I change or try to navigate in Portugues.

Because it can be?
Drupal version: 8.3.7
Drush version: 9.0-dev-g105e0aa


texts: How to add the Terms and Conditions to custom form,not using any profile 2 or webform module?

texts:
How to add the Terms and Conditions to custom form?
 i have made a module and willing to add a "read me / terms and conditions " type of thing to my form .

Whole code can be seen here , just dont wanted to write it again .
Custom module error, does'nt show on the page

Please suggest.


texts: How to combine 2 exposed filters (String and Taxonomy field)

texts: I need to create a View with a search box for my content type; the search string has to match both title OR a CCK taxonomy field. Is there a Views module that permits to do it? I've tried http://drupal.org/project/views_filters_populate but it only works with 2 string fields.


texts:
I have created a custom resource which extends the EntityResource class. This way I can use all build in functionality that Drupal core provides on the default entity resource, but I can still add some extra checks. This works perfectly fine.

I defined my canonical route in my resource as /api/my-endpoint/{node}. In this way, I can fetch and patch nodes by the node ID. After careful consideration, I want to implement /api/my-endpoint/{node_uuid} or even /api/my-endpoint/{node_custom_field} to fetch (and patch) a node by UUID.

Of course, Drupal doesn't know this param and cannot load the corresponding node object, which results in fatal errors.

How can make I this work?
I tried to implement a custom RoutingParamConverter class, but I didn't got it to work.


texts: User contributed image gallery, per node

texts:
Working on a new Drupal 7 based site.  Put together a few sites back in the 5 days, but lots has changed.

I'm looking to allow users to upload images to a particular content type, and to show those images as a gallery.  Restated - I'd like user X to be able to create a node, and then users X, Y, Z, P, D, and Q to each be able to upload images to that node.  (Looking to the future, I want people to vote on images, but let's keep it simple, for the moment.)

My sense at this point is that I have to create an entity type for image, use entity reference to point from the images to their parent node, and use views and probably eva to show the galleries on the parent node.

Question 1: Am on the right track here?

Question 2: How should I handle the 'allow anyone to upload images' piece?  I'd like there to be a rather simple opportunity, when a user is viewing a parent node, to upload an image or provide an image url, and for the image node to be created and appropriately associated.

Thanks for any help.


texts:
I'm using a twig template for a custom block that have images to link to specific nodes. I actually have the node IDs, however generating a relative link doesn't always work. Some pages are using aliases like so
127.0.0.1/web/products and some are using nodes like 127.0.0.1/web/node/19
so using the same relative link doesn't always work. Note that my drupal instance is within a /web/ folder and not at just 127.0.0.1

My twig template looks like this

    {% for key, image in imageurl %}

            {{ block_title[key] }}

    {% endfor %}

When it appears on 127.0.0.1/web/products the link is

http://127.0.0.1/web/node/15

When it appears on 127.0.0.1/web/node/19 the link is

http://127.0.0.1/web/node/node/9

The image has the same issue, since 'image' only contains the filename.
Is there a way I can automatically generate a link based on a node ID and a file that I know the path to, to account for URLs that may contain aliases?


texts:
I'm testing page_manager on a fresh install of Drupal 8 (V 8.1.8).

I installed :

Layout Plugin 8.x-1.0-alpha22
Panels 8.x-3.0-beta4
Page Manager 8.x-1.0-alpha24 (with page_manager_ui)

When I try to create a Panel variant in a custom page, I've got no option to insert a block...

My UI appears like that :

Where can I add content in this page ?


texts: Drupal 8 Theme Header Background Image Upload

texts:
I'm upgrading the Mayo theme to Drupal 8. For Drupal 7 it worked like this in theme-settings.php with hook_form_system_theme_settings_alter():

  $form['adv_header']['header_bg'] = array(
    '#type' => 'file',
    '#title' => t('Upload header background image'),
    '#size' => 40,
    '#attributes' => array('enctype' => 'multipart/form-data'),
    '#description' => t('If you don\'t jave direct access to the server, use this field to upload your header background image'),
    '#element_validate' => array('mayo_header_bg_validate'),
  );

element_validate in the above called:

/**
 * Check and save the uploaded header background image
 */
function mayo_header_bg_validate($element, &$form_state) {
  global $base_url;

  $validators = array('file_validate_is_image' => array());
  $file = file_save_upload('header_bg', $validators, "public://", FILE_EXISTS_REPLACE);

  if ($file) {
    // change file's status from temporary to permanent and update file database
    $file->status = FILE_STATUS_PERMANENT;
    file_save($file);

    $file_url = file_create_url($file->uri);
    $file_url = str_ireplace($base_url, '', $file_url);

    // set to form
    $form_state['values']['header_bg_file'] = $file_url;
  }
}

For the Drupal 8 version I have added use Drupal\Core\Form\FormStateInterface; at the top of theme-settings.php and some changes to mayo_header_bg_validate(). So far it looks like this:

/**
 * Check and save the uploaded header background image
 */
function mayo_header_bg_validate($element, FormStateInterface $form_state) {
  global $base_url;

  $validators = array('file_validate_is_image' => array());
  $file = file_save_upload('header_bg', $validators, "public://", NULL, FILE_EXISTS_REPLACE);
  if ($file) {
    //change file's status from temporary to permanent and update file database
    $file->status = FILE_STATUS_PERMANENT;
    //file_save($file);

    $file_url = file_create_url($file->uri);
    $file_url = str_ireplace($base_url, '', $file_url);

     //set to form
    //$form_state['values']['header_bg_file'] = $file_url;
    $form_state->setValue(['header_bg_file'], $file_url);

  }
}

It does upload the image to /sites/default/files and put an entry into the file_managed table. file_save() is gone for Drupal 8 and I couldn't find a change log showing how to replace it for Drupal 8. 'header_bg' just shows a value of "/" in mayo.settings.


texts: cant loop through array with ajax_command_html

texts:
im beginner in drupal and i would like to ask why is this not looping , it just gives me first result

$string = $form_state['values']['search_block_form'];

  $query=db_select('node','n');
$query->join('field_data_body','b' , 'n.nid = b.entity_id');

$query
->fields('n',array('nid', 'title'))
->fields('b', array('entity_id', 'body_value'));

  $db_or = db_or();
  $db_or->condition('n.title', '%' . db_like($string) . '%', 'LIKE');
  $db_or->condition('b.body_value', '%' . db_like($string) . '%', 'LIKE');
  $query->condition($db_or);

  $result = $query->execute();

while ($row = $result->fetchAssoc()) {
      $node_title = $row['title'];
      $node_id = $row['nid'];
      $entity_id = $row['entity_id'];
      $body_text = $row['body_value'];

  $commands[] = ajax_command_html("#block-system-main", "<h1> $node_title </h1> <p> $body_text </p>"  );
  return array('#type' => 'ajax', '#commands' => $commands);

}

I want replace div with id block-system-main with found content


texts: Hiding menu item depending on specific access

texts:
I work on a D8 (8.6)
I want to hide some item on my menu depending on route param onto this link.

When I try to access the route I get a 403 error and works as expected but the the link inside the menu is still displayed.

I create a custom Accessinterface which return an AccessResult::allowed() or denied() depending on my rules.

Is there a core solution to prevent the link to be displayed on the main menu or I have to handle it in JS ?

My CustomAccessCheck :

class CustomAccessCheck implements AccessInterface
{

  public function access(AccountInterface $account)
  {
    $isAuthenticated = $account->isAuthenticated();

    try {
      $currentGroup = TestEntity::getInstance()->currentGroup;
    } catch (InvalidPluginDefinitionException $e) {
      return AccessResult::forbidden();
    }
    if ( $isAuthenticated &&
      ( !empty($currentGroup["id"]) && isset($currentGroup["IsActive"]) && $currentGroup["IsActive"])
    ) {
      return AccessResult::allowed();
    }
    return AccessResult::forbidden();
  }
}

I configure services and routing.yml in order to run this AccessChecker.
The custom menu contain some menu items which target the route configured.

My problem is even if the user don't have access to the route the menu item is displayed.

Thanks for help
Nico


texts: display different header text if view has taxonomy term

texts: I have a view which displays different taxonomy terms, I would like to set a different "header text" depending on what term the view is filtering by. Right now whatever header text I choose I can only apply to all pages of the view. I would like to display different header text depending on what term is being filtered.


texts: How do I change the input type of an exposed filter in a view?

texts:
I have a view which lists products. I created an exposed filter based on price criteria.

The exposed filter shows a text input where you can type an integer number to get the products filtered. What I need is to replace the text input with a select list showing values such as 50000, 100000, 1500000, 200000.

I have the Better Exposed Filters module, and the Views PHP module enabled.


texts: How can I create an "allow anything" field on a node?

texts:
We're building a site and need to allow our users to have a field on the node that will allow for ANY content: scripts, iframes, script files, css files, etc; essentially embed codes for mailchimp forms, donation forms, etc.

This HAS to be something the user can do so. Can I create a textarea field and then override a hook or something to prevent that fields contents from going through any sort of filtering?

I also completely understand the risks here. We don't have any public users logging into the site. We know everyone who is logging in.


texts: How to create optgroups from taxonomy terms?

texts:
I have taxonomy terms with parent/child hierarchies (1 level deep). On a node edit page the terms are shown in a select box where I can select multiple terms.

What I'm trying to do is convert the parent terms into optgroups so they cannot get selected and the children are nicely grouped. This post shows how to structure the form array.

Basically, the array needs to get arranged like this:

$form['field_disc_topic']['und']['#options'] = array (

   'parent1' => array(
    3 => 'child1',
    4 => 'child2',
    5 => 'child3',
    ),
    26 => 'parent2' => array(
    8 => 'child1',
    9 => 'child2',
    ),
);

This is the code I started with. A parent term has depth=0, children have depth=1. I can't figure out to how build the array:

$tax = taxonomy_get_tree(2);
for ($i = 0; $i < count($tax); ++$i) {
    debug( $tax[$i]->tid);
    debug($tax[$i]->name);
    debug($tax[$i]->depth);
}

Can anyone solve this? Or is there an easier way to do this?


texts: Creating a Module Level Main Menu Replacement

texts:
I am looking to create a module (not theme) that replaces/augments the main menu in Drupal 7.

I've got a CSS driven menu (MegaMenu style). It's generic and I want to reuse it across projects/themes... thus my desire for a module.

(NOTE: I'll also be taking this to WordPress plugin, so maintaining reusable core code is a high priority. Drupal or WordPress themes, can respin my basic styles for visual integration.)

Creating a module to inject my CSS was easy enough, then I tested with Bartik which doesn't expand child menu items.

I believe I should be overriding theme calls to links__system_main_menu.

Everything I've found (specific enough to be useful) resolves around template.php and THEMENAME_links__system_MENU_NAME.

I'm not getting anything when I try replacing THEMENAME with MODULENAME (i.e. MODULENAME_links__system_main_menu).

I've also looked at hook_menu and hook_menu_alter, but I'm just not seeing a reliable or elegant way to do this.

The most concise example of what I'm looking to do (in a theme-based approach) is: Turn your main menu into a Superfish menu

TLDR: How can I ensure that Main Menu is written out in expanded tree mode without relying on theme level code?

I realize there will likely be a need to override/prune any existing Main Menu theme styles.