18

How do I display/edit the machine name for a View?

Reason for asking is that I tried cloning a view but the name I gave was rejected because it had already been used but I couldn't see where.

17

You can export view, change values, delete original and import view back.

There is a import option in the views listing page. Just paste this url after your current url and you will see the import views page. By seeing your tags I am assuming you are using Drupal 7, so the given below url will work only for Drupal 7.

Below is the url to be added :

#overlay=admin/structure/views/import

To export view:

  1. go to /admin/structure/views

  2. under 'operations' column click on arrow and select 'export'

  3. copy code and edit/change in external editor

  4. go to /admin/structure/views/import and import changed view You can first delete existing view or select 'Replace an existing view if one exists with the same name' on the import settings –

| improve this answer | |
  • Can you please explain the process of exporting a view ? – niksmac Dec 13 '12 at 2:02
  • shortcut cut way – monymirza Dec 13 '12 at 5:13
  • /admin/structure/views/import – Zdenko Vujasinovic Dec 13 '12 at 8:17
  • 1
    @nikhil-m To export view: 1. go to /admin/structure/views 2. under 'operations' column click on arrow and select 'export' 3. copy code and edit/change in external editor 4. got /admin/structure/views/import and import changed view You can first delete existing view or select 'Replace an existing view if one exists with the same name' on the import settings – Zdenko Vujasinovic Dec 13 '12 at 20:12
  • +1 changing this to be the accepted answer because it answers fully my question: 1. to view the machine name and 2. edit it. I also like this solution because it requires the minimum amount of code and setup to do (no code to be written and no dependencies). In addition is shows how to export the view itself - which I think will be very useful for automated builds of Drupal sites (with drush, drush make), source code management and making similar views from existing quickly. Thank you! – therobyouknow Dec 27 '12 at 12:18
9

I don't think you can change the machine name of a view, at least not in the UI. You can see the machine name in the URL if you mouse over the "edit link".

| improve this answer | |
  • I'll check this out. – therobyouknow Nov 14 '11 at 14:46
  • +1 & accepted @mototribe this works. Shame they couldnt display it permanently rather than having to hover though. – therobyouknow Dec 12 '11 at 2:21
  • update: good partial solution - thanks - I have moved the accepted flag to another answer that provides a solution for changing the machine name. – therobyouknow Dec 27 '12 at 12:19
6

You can clone it with the new machine name.

Update: How to display the machine name for a View.
You can see list of all views in your Drupal installition using this code:

$views = views_get_all_views();
// Optional: views objects are big so unset large members
foreach ($views as $machine_name => $view) {
  unset($view->display, $view->localization_plugin);
  $views[$machine_name] = $view;
}
// Print array keyed by views machine name
dpm($views);

You can run this code on page devel/php (needs Devel module).
There will be printed array of views keyed by machine name and you will be able to find your lost view.

Update: You can search views by machine name at views list page in Drupal 7. For this you should turn on flag "Show filters on the list of views" in Views settings.

| improve this answer | |
  • 1
    The question is, "How do I display/edit the machine name for a View?" – kiamlaluno Nov 11 '11 at 8:24
  • +1 @kiamlaluno. kalabro I'm surprised that it takes some custom code to achieve this. – therobyouknow Nov 14 '11 at 14:45
  • This is one time debug code, which you can run to look through your views. There are no column with views' machine_name in standard list of Views. And there are no DB table with all views, because some views are stored in code. – kalabro Nov 14 '11 at 14:56
4

$page["#views_contextual_links_info"]["views_ui"]["view_name"] - By using this variable you can get the machine name of your view.

| improve this answer | |
0

You can change the value of the name field in the views_view table in the database. Not always the best idea, since you can end up breaking references to the blocks/pages in parts of the site, such as in panels.

| improve this answer | |
  • Terrible advice, this will break your site. – Danny Englander Jun 5 '13 at 15:08
  • Not if you are smart about it and replace the block/pane/etc. Just as much work as cloning – Mark Cameron Jun 5 '13 at 19:57
0

I don't believe you can change the machine name of a view once you've created it and finding the machine name is not at all intuitive. I imagine this may be because the only people who would be needing the machine name would be programmers and fairly advanced power users who can handle some obfuscation to make the interface easier to understand for everyone else.

To find the machine name of the view, just go to your views list and hold your mouse over any part of the row. It doesn't have to be the edit button. This is not an official JavaScript mouseover so your browser may choose to render it in a different way than I'm seeing or perhaps even not render it at all. In those cases, you can peek at the HTML source and you'll notice that in the tag of the view row that you're looking at, there's a title attribute that will read something like .

If you want the machine name of a display inside the view, that's a little easier. That's in the Advanced block of the views edit interface. It's in there somewhere and it's labeled as "machine_name" so there aren't any special tricks to uncover it. Unlike the view's machine name, you can change this one.

So what do you do if you need to change the machine name of the view? Well, you could get crunchy with the database and manually edit it to update the machine name everywhere that it's used, but this is too much trouble in my opinion. There's a far easier way. Just clone your view and give it the machine name you really wanted. After it's cloned, you can delete the original one that had the wrong machine name.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.