Skip to Content

Drupal

Drupalize.Me: We Want to Know: Got Plans for Learning Drupal 8?

Planet Drupal - 13 May 2014 - 6:00am
Hey Drupal community! Drupal 8 is on the horizon, and Drupalize.Me is gearing up to produce hundreds of new videos. Before getting started, we want to know what training you need. Please tell us by completing the following survey. For your time, we'll give you $20 toward a Drupalize.Me membership. Thanks!
Categories: Drupal

Blair Wadman: Recreate a Drupal Feature

Planet Drupal - 13 May 2014 - 5:09am

In the first part of this Drupal Features guide, you learned why Features is a vital tool for Drupal site builders and developers. We then created a new Feature, which contained a Todo list content type. In this part, you will create a View to display the todo list in a block and add the View to the Feature by recreating it. Views are not the only thing you might add to a feature module. You can add a whole range of components, such as image presets, context and strongarm (for variables) to an existing feature.

Tags: FeaturesDrupal Site buildingPlanet Drupal
Categories: Drupal

Ryan Szrama: Beware InnoDB's auto_increment reset on reboot

Planet Drupal - 12 May 2014 - 8:00pm

Earlier this year I helped my friend Samuel bring his used cell phone resell business online using Drupal Commerce. The site is still in maintenance mode while we finish the self-service features, but his staff currently uses it logged in from their various locations as their point of sale system. Knowing the ins and outs of Commerce, I didn't have any problems tailor making an eCommerce application for his business, but I did have one hiccup during deployment that I'd never seen before.

We built Wikiwoo.com on Pantheon, a Drupal Platform as a Service, using a free developer site until it was ready for use in stores. Pantheon really helped us collaborate on the site build, with me doing the coding and configuring while he filled the product catalog. We did everything on the site's dev environment, including letting his partners take a look around to find things worth fixing, until we were ready to go live.

One of the last things I did to prepare for the launch was update the auto_increment value of the commerce_order table to account for the number of orders they processed in the previous year and a half. However, we weren't really migrating old eCommerce data, so I just expected the first order on the new site to start where we wanted and we'd watch them grow from there. A quick test showed it working as expected, so I deleted the dummy orders and sent him a link to upgrade the account to a paid plan to take it live.

Unfortunately, when I went back to the site the next day, I saw that orders were being created with IDs starting back at 1. I knew there was nothing in Commerce that would effect such a change, so I hit up Pantheon support and got a quick confirmation that nothing they do would intentionally reset auto_increment values either.

Sidebar: I really should emphasize quick. Any time I've ever contacted Pantheon support, they've responded right away. "Groovy," said Josh Koenig in this particular instance when we nailed down what was happening. "Groovy," I say to Pantheon's customer service.

It turns out what I experienced was a result of InnoDB's treatment of auto_increment values. The auto_increment counter is only stored in memory, not on disk, and it is recalculated on server startup. InnoDB simply looks for the highest used ID and sets the counter to the next value, explaining why my order IDs shrunk back down to 1 after I cleared out all of our dummy orders.

In our case, it was the upgrade from a free account to a paid account that restarted the database server, triggering the reset of the counter. However, with cloud based Platforms as a Service, I imagine there are other scenarios where an expected alteration to an auto_increment value is apparently "lost" on migration between environments or builds. This is probably mostly an eCommerce issue with respect to Drupal sites, as merchants often want or need order IDs to account for historical sales, but perhaps the tip can save someone else a bit of head scratching.

To get around my issue, I simply reset the auto_increment to where I wanted it to be, created a cart order for myself, and waited for a real order to be created before deleting my dummy order.

Problem solved, it's been fun to watch the order count grow from there.

Photo credit: Max Barnes

Categories: Drupal

Midwestern Mac, LLC: Drupal and Node.js at STLJS Meetup - Thursday, May 15!

Planet Drupal - 12 May 2014 - 7:18pm

I'll be presenting Node.js and Drupal — Working Together at the STL.JS meetup this Thursday, May 15, at The Able Few in St. Louis.

In the presentation, I'll basically be covering how Server Check.in uses Drupal and Node.js to deliver a simple, fast, and stable server monitoring service. During the course of the presentation, I'll touch on why and how Server Check.in was built, how Ansible is used to maintain the infrastructure, and the effectiveness of lightweight marketing, blogging, and 'low end box' servers.

Categories: Drupal

2bits: Configuring Apache Solr 4.x for Drupal, with password authentication

Planet Drupal - 12 May 2014 - 12:34pm
Most of high traffic or complex Drupal sites use Apache Solr as the search engine. It is much faster and more scaleable than Drupal's search module. In this article, we describe one way of many for having a working Apache Solr installation for use with Drupal 7.x, on Ubunutu Server 12.04 LTS. Objectives For this article, we focus on having an installation of Apache Solr with the following objectives: Use the latest stable version of Apache Solr

read more

Categories: Drupal

AGLOBALWAY: Drupal CKEDITOR configuration to work with bootstrap theme

Planet Drupal - 12 May 2014 - 11:55am

Drupal and Bootstrap theme are awesome, but when it comes to use ckeditor you can loose some nice framework styles and it can break your responsive website by adding a simple image or table. One of the ways of fixing it is using a simple configuration to extend and adjust ckeditor.

Adding Boostrap Components to your ckeditor styles and adding extra configuration to ckeditor.config.js

Before we start copy the sites/all/modules/ckeditor/ckeditor.styles.js and sites/all/modules/ckeditor/ckeditor.config.js file into your theme directory (themes/bootstrap/), and enable them in your ckeditor profile (in CSS tab Predefined styles chose “Define path to ckeditor.styles.js” and change Predefined styles path to “%t/ckeditor.styles.js” and in ADVANCED OPTIONS tab check Load ckeditor.config.js from the theme path to yes). You will need to also enable “styles” menu in your ckeditor toolbar and you may want to use your theme styles to preview ckeditor styles before saving your content.

  1. Open your ckeditor.styles.js, and comment or remove all useless styles. if(typeof(CKEDITOR) !== 'undefined') { CKEDITOR.addStylesSet( 'drupal', [ ]); }

    You should have something like this

  2. 2. Copy new bootstrap styles in your ckeditor.styles.js. And save the file /* Bootstrap Styles */ /* Typography */ { name : 'span.H1' , element : 'span', attributes: { 'class': 'h1' } }, { name : 'span.H2' , element : 'span', attributes: { 'class': 'h2' } }, { name : 'span.H3' , element : 'span', attributes: { 'class': 'h3' } }, { name : 'span.H4' , element : 'span', attributes: { 'class': 'h4' } }, { name : 'span.H5' , element : 'span', attributes: { 'class': 'h5' } }, { name : 'span.H6' , element : 'span', attributes: { 'class': 'h6' } }, { name : 'Paragraph Lead' , element : 'p', attributes: { 'class': 'lead' } }, { name : 'Unstyled List', element : 'ul', attributes : { 'class' : 'list-unstyled' } }, { name : 'List inline', element : 'ul', attributes : { 'class' : 'list-inline' } }, { name : 'Table', element : 'table', attributes : { 'class' : 'table' } }, { name : 'Table Striped rows', element : 'table', attributes : { 'class' : 'table table-striped' } }, { name : 'Table Bordered', element : 'table', attributes : { 'class' : 'table table-bordered' } }, { name : 'Table Hover rows', element : 'table', attributes : { 'class' : 'table table-hover' } }, { name : 'Table Condensed', element : 'table', attributes : { 'class' : 'table table-condensed' } }, { name : 'Image shap rounded', element : 'table', attributes : { 'class' : 'img-rounded' } }, { name : 'Image shap circle', element : 'table', attributes : { 'class' : 'img-circle' } }, { name : 'Image shap thumbnail', element : 'table', attributes : { 'class' : 'img-thumbnail' } }, { name : 'Image float left', element : 'table', attributes : { 'class' : 'pull-left' } }, { name : 'Image float right', element : 'table', attributes : { 'class' : 'pull-right' } },
  3. Open your ckeditor.config.js, search for “config.justifyClasses” and replace it with this line: config.justifyClasses = [ 'text-left', 'text-center', 'text-right', 'text-justify' ];

    This will change default text alignment classes to new bootstrap classes

  4. At very bottom of ckeditor.config.js, copy and paste this lines. CKEDITOR.on('dialogDefinition', function( ev ) { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; if(dialogName === 'table' || dialogName == 'tableProperties' ) { var infoTab = dialogDefinition.getContents('info'); //remove fields var cellSpacing = infoTab.remove('txtCellSpace'); var cellPadding = infoTab.remove('txtCellPad'); var border = infoTab.remove('txtBorder'); var width = infoTab.remove('txtWidth'); var height = infoTab.remove('txtHeight'); var align = infoTab.remove('cmbAlign'); } if(dialogName === 'image') { var infoTab = dialogDefinition.getContents('info'); dialogDefinition.removeContents( 'Link' ); dialogDefinition.removeContents( 'advanced' ); infoTab.remove('txtWidth'); infoTab.remove('txtHeight'); infoTab.remove('txtBorder'); infoTab.remove('txtHSpace'); infoTab.remove('txtVSpace'); infoTab.remove('ratioLock'); infoTab.remove('cmbAlign'); } });

    This will remove default inline styles like a width and height from image/table configuration popup.

Reference:
https://drupal.org/project/bootstrap

Tags: drupaldrupal planet
Categories: Drupal

Get Pantheon Blog: Moving MySQL tables from MyISAM to InnoDB

Planet Drupal - 12 May 2014 - 10:00am

One of the greatest things ever to happen to MySQL was the InnoDB engine. Before InnoDB, indexes would get corrupted, updates meant table locks, not just row locks, and we had no support for transactions. Since the advent of InnoDB however, we've come a long way. These days, most serious DBAs using MySQL build exclusively on the InnoDB engine.

Sadly though, many sites are still using the MyISAM engine. Some are hosted on shared hosting servers and some just don't have a proper DBA to look after their databases. For whatever the reason, these sites are missing out on the performance and stability gains that the rest of us take for granted. At Pantheon, we know there are a lot of these sites out there because we see them when they migrate their sites onto our platform. As part of our Launch Check, we check the engine type on every table. If we find a table using the MyISAM engine, we notify the user so they can fix it.

Fixing this problem is simple to any developer who understands a little SQL. However, for non-developers, this can be a daunting task. So I have put together a little PHP script to help you convert your MyISAM tables to InnoDB.

NOTE: This is an unofficial script. It is not supported by Pantheon. Customer Support will not help you run it, nor will they hold your hand while fixing things if this script screws up your database. Use THIS SCRIPT AT YOUR OWN RISK. I strongly suggest you make a backup of your database before running this script. 

The Easy Way

Still with me? Cool! Let's dive right in. 

There are 2 versions of this script. One is meant to be called from a web browser. It is meant for Pantheon customers. If you are a Pantheon customer, save the code in a file with the extension .php and sftp it up to your site. Place it in the code directory of your website.

Now, point a browser to your newly created script that should be in the root directory of your Dev environment.

http://your.dev.url.gotpantheon.com/filename.php

That is all there is to it. The script will do all the work. You don't need to change anything.

Here is the browser version of the script:

The Developer Way

If you are not a Pantheon customer, or you want to run the script from the command line, use the one below. To use this one however, you need to know two things before you begin.

  1. You have to have PHP installed on the computer you want to run this on. I run this on my laptop. I have PHP installed on my laptop. I know that because I can type php -v at the command line and I get a proper response. If you do not understand any of that, this script is not for you, use the one above.
  2. If you are a Pantheon customer, you can get your database connection info from your site's dashboard. Make sure you get the information for your Dev environment. After you've run the script, and everything looks good, you can easily migrate it up the line to Test and then Live. If you are running this on your site and your site is not on Pantheon, you will have to find another way to get your MySQL connection info.

Here is the command line script:

See the line that says "* DO NOT CHANGE ANYTHING BELOW THIS LINE"? I'm serious about that. If it doesn't' work and you are not a programmer, don't mess with it. If you are a programmer, you realize exactly how dead-simple the script is.

Here are the parameters you will need to configure before running the script.

  • host = This is the name of the machine your db is running on. If you are a Pantheon customer localhost is WRONG. Get the correct host and paste it in there replacing localhost. 
  • port = This is the port that is running MySQL on your computer. Again, if you are a Pantheon customer, we give you this information. If you are not, 3306 is the standard port for MySQL. 
  • user = This is the user name you use to connect to MySQL with. 
  • password = This is your MySQL password for the user you specified in the line above.
  • database = This is the name of the database that contains the tables. If you are a pantheon customer, this is "pantheon". If you are not a Pantheon customer, you will need to get this from your host.

Now, save the file.

Then from a command window execute the program. (How you get a command window varies by OS. If you don't know, ask your computer friend, younger sibling, or niece.)

The script will tell you everything it is doing. It has safeties built in to keep it from changing anything by MyISAM tables. It will look at every table in your database and if the engine is MyISAM, it will change it to an InnoDB.

Once you have run it successfully, check everything! 

This is not a particularly dangerous script. The change is pretty simple. However, it's your data. So be careful. 

Blog Categories: Engineering
Categories: Drupal

drunomics: #d8rules - Supporting the Rules modules for Drupal 8

Planet Drupal - 12 May 2014 - 9:12am

Today, I've the pleasure to introduce the #d8rules initative, our combined effort to get the Rules module ported to Drupal 8 in time!

Drupal 8 is coming...

Fortunately, the first beta of Drupal 8 is coming closer so it's time to make sure all the modules are ported and ready for Drupal 8. Unfortunately, the Rules module - my long term number one contributed module - is about to be left behind. I've worked a lot on Drupal 8 to get critical Entity API improvements like the new Entity Field API (called Entity Property API at the time of the introduction) as well as the new Typed data API done. Of course, the work on core is time intensive, not "done" yet and won't stop - so there is not a lot contribution time left for my contributed modules. :/

So where is Rules for Drupal 8 now?

In short, it's not there yet. While quite a bit of work under the hood and planning has been done already, the main work - porting of the module itself - is still to be done. As Drupal 8 ships with quite a bunch of important improvements, this requires the rewrite of significant parts of the module. In Drupal 7, the Rules module had to solve a lot of hard problems like handling its configuration, configuration translation, dependency tracking, integrity checks and plugins, which all have solutions in Drupal 8 core now. That's awesome, but it requires us to adapt the previous Drupal 7 solutions to work inline with Drupal 8 best practices. However, more than that - the foundational metadata Rules needs is already there as well!

The foundation is (mostly) there

In Drupal 7 the creation of the Entity API module, in particular its Entity Metadata wrappers and the backing Entity Property Information, was driven by the needs of the Rules module. While the Rules module makes it simple to work with data for site builders, the Entity module makes it simple for developers first. Subsequently, the Rules module can build upon the easy API and make it accessible via the rule model and its UI. For Drupal 8, the Entity Field API and its underlying Typed Data API are that easy API upon which the Rules module can build upon. That's great, as it means we have the foundation we can build upon in place - but again, it changed (improved) substantially and will require us to adapt a lot of what's there. However, having the Typed Data API and all the necessary metadata built-in means that the out of the box module and entity type support of Rules for Drupal 8 will be substantially better as well.

Actions and conditions in core

We've got an Actions and Conditions API in core already, so one might think another huge part has been taken care off. Unfortunately, no - those APIs have been created/ported with other use cases in mind, so they do not cater for all the more advanced features Rules users are used to. While I tried to make sure they fit Rules needs as far as possible when they were introduced/updated, they do not fit our needs yet and it might be impossible to make them fit without breaking those APIs. For Rules 8.x we plan to work on improving those APIs (from contrib) as needed first, so we can ensure they fit Rules' requirements. Once we are sure everything works out we'll know what we have to adapt and whether improvements can be contributed to core. Depending on how that works out, we'll see whether we can build up on the core Action and Conditions API or there will be Rules' variants of those APIs (again :(). For more details please see the related issues:

We have a plan

We've quite some work to do to get Rules ported to Drupal 8. klausi and me estimated the task to be additional 1050 hours work (from here). With us, working on it in our spare time besides our other contributions (Entity Field API, Rest module in core, ..) we figured the module won't be ready before sometime in 2015, not unlikely even 2016. That's obviously too late, so we'd love to invest more of our time and work on it during work hours as well, such that we can deliver a ported version in 2014. Our companys cannot afford taking that investment alone, but are up for supporting us and enable us to work on a community rate of € 45/h net cost for the project. You can find more details on the project plan and estimations on our initative site.

Rules needs your help!

If you think the Rules module is a valuable tool and helps you building sites faster, please consider supporting our iniatitive! There is a limited goodie for the 50 first supporters pledging >65$ - check it out. If you are going to Drupalcon Austin and you'd love to help, consider signing up for the #d8rules sprint! We'll get started porting either events, conditions or actions to the new API. Lastly, please help to spread the word! We've got supporter badges that you can embed on your site, and obviously our hash tag is #d8rules!

Video of #d8rules

 

Resources

Iniative website: http://d8rules.org
drupalfund.us campaign: https://www.drupalfund.us/project/d8rules-support-rules-module-drupal-8
Project page: http://drupal.org/project/rules

Categories: Drupal

Stanford Web Services Blog: Module of the Day: JS Injector

Planet Drupal - 12 May 2014 - 9:09am

Today's "Module of the Day" is a handy little module called JS Injector that allows you to insert snippets of Javascript into your site.

In this post, I'll walk through how to enable and configure the module, use it to shout, "Hello, World!", and then go into some more advanced configuration.

Categories: Drupal

Web Omelette: Sending HTML Emails with Webform in Drupal 7

Planet Drupal - 12 May 2014 - 12:12am

Have you ever wondered how you can include HTML markup in the emails you send with Webform? Out of the box, you cannot. But I am going to show you a simple way to achieve this using the Mime Mail module and some simple theming. Additionally, I will show you how to control which webforms should send HTML emails and which should not.

First though, make sure you install and enable the Mime Mail and Mail System modules (the latter is a dependency of the former). With Drush, all you have to do is use this command:

drush en mimemail -y

It will take care of all you need to do. If you commit the module to your repo, don't forget that the Mail System module also gets downloaded, so make sure you include it as well.

Next, edit your theme's template.php file and paste this block of code (explained after):

function your_theme_webform_mail_headers($variables) { $headers = array(); $headers = array( 'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes', 'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')', ); return $headers; }

Make sure you change your_theme with the name of your theme. So what happens here? We override the theme_webform_mail_headers() declared by the Webform module. We do this in order to add a content type to the mail headers, and set it to HTML. And that's pretty much it.

If you now clear your caches and test a webform, you'll see that you can add anchor tags and other basic HTML tags.

One problem you might run into though is that all your webforms are now sending emails in HTML format - a result only partially desired. You'll notice that the default email that you send no longer provides any spacing and all the text gets put on one line - as HTML in fact.

So what you can do is make a selection of webforms for which you'll want HTML emails. A handy way of doing this is by adding a field to your webform content type that will be used to swith HTML emails on/off for a given node. So to illustrate this, let's say we added a new field to the relevant content type called HTML Emails (with the machine name: field_html_email). This field is a boolean type (a single checkbox basically) with the values of 1 for on and 0 for off.

It follows to adapt the theme override above and replace it with something like this:

function your_theme_webform_mail_headers($variables) { $headers = array( 'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')', ); // Get the HTML Email field $html_email_field = field_get_items('node', $variables['node'], 'field_html_email'); // Check if this webform node needs to send HTML emails if (!empty($html_email_field)) { $html = $html_email_field[0]['value'] == 1 ? TRUE : FALSE; } if ($html === TRUE) { $headers['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes'; } return $headers; }

If you consult the documentation for this theme function, you'll know that the $variables parameter contains also the node object which uses Webform to send the email. So we basically check for the value of our field and if it is 1, we add the HTML information to the mail headers. Otherwise, we return the $headers array containing the value it does by default (essentially making no changes).

You can now clear the caches and test it out. Edit a node of the respective content type and check the box. You'll see that it now sends HTML emails. However, if you uncheck the box, it will fallback to the default format that comes with the Webform module.

Hope this helps.

In Theming | Drupal var switchTo5x = true;stLight.options({"publisher":"dr-8de6c3c4-3462-9715-caaf-ce2c161a50c"});
Categories: Drupal

Ryan Szrama: Beyond Wombats

Planet Drupal - 11 May 2014 - 7:35pm

I accidentally started publishing open source software in 2006, the first integration of the QuickBooks Web Connector with anything. This was pre-Ubercart when I was just cutting my teeth on PHP / MySQL development at Prima Supply, and I thought it would be fun to claim the code was written by wombats while I just published it online. I decided to own the silliness and start blogging on bywombats.com using Drupal 4.7 at the time - and immediately picked up a freelance contract doing QuickBooks integration work.

Topics: DrupalWork
Categories: Drupal

Drupal Association News: Join Us for the Next Drupal Association Board Meeting

Planet Drupal - 10 May 2014 - 10:14am

Things continue to move really quickly at the Association. With DrupalCon Austin less than a month away, we're also moving forward on DrupalCon Amsterdam, DrupalCon Latin America, and lots of non-DrupalCon projects as well. Join us at this meeting to get more background on the lastest happenings at the Association. This month, we will fetaure an update on DrupalCon Latin America as well as an update and Q&A with the new Drupal Association CTO, Josh Mitchell.

You can listen in and ask questions at the board meeting on Wednesday, 14 May at Noon Pacific, 7pm UTC. There are several ways to join or learn more:

VOIP Audio and Video

IRC: #drupal-association

Meeting Materials

We look forward to seeing you there!

Categories: Drupal

Drupal 8 and iOS: How to DELETE a node from Drupal 8 with iOS device ?

Planet Drupal - 10 May 2014 - 6:12am
How to DELETE a node from Drupal 8 with iOS device ?

In this tutorial I will teach you how to use NSURLSession dataTask to delete a node from Drupal 8 via REST services.

It is required that you have enough permission to delete any content via REST. To check that navigate to /admin/people/permission on your Drupal 8 site. Here I am assuming that you have REST enabled on your site.  You should give DELETE permission to Admin and Authenticated user only as shown in flowing figure.

One other thing I want to mention here is you have to add basic_auth as supported_auth for DELETE method for entity:node in your rest.settings.yml file. But as in alpha 11 settings files are not getting generated I would suggest you to use REST UI ( https://drupal.org/project/restui ) contributed module for this purpose.

rest.settings.yml for DELETE

 Now add new simple page on your Drupal site and remember its node ID. Ok this is for Drupal side. Now let’s move on to our iOS application.

Storyboard for this app

 Our app just have one button and on label as shown in figure. Here you will type node ID in text field and click on “Delete Node” button.

 

As we have hook up “deleteNode” method with “Delete Node” button on clicking “Delete Node” button following method will get executed.

This method creates new NSMutableURLRequest and sets it http method to “DELETE”. Now it will create NSURLSessionConfiguration object and sets appropriate headers like “Authorization”. Here we are using http basic auth. Finally we create NSURLSession and NSURLSessionDataTask and resume the task.

 

After successful deletion you will get notified by app.

Here is code for method that will be called when “Delete Node” button is pressed.

 

- (IBAction)deleteNode:(id)sender {

    

    [self.nodeDetailsTextField resignFirstResponder]; // just tom make keyboard go away

    

    NSString *nodeID = [self.nodeDetailsTextField text]; // node ID as string

    

    NSURL *baseURL = [NSURL URLWithString:@"http://tntfoss-vivekvpandya.rhcloud.com/node/"];

    

    NSURL *nodeURL = [baseURL URLByAppendingPathComponent:nodeID]; // create node ID like "baseURL/node/1"

  

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:nodeURL];

    

    [request setHTTPMethod:@"DELETE"]; // make request a "DELETE" request

    

    NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; // get the default configuration object

    

    NSString *userNamePassWordString = [NSString stringWithFormat:@"username:pasword"];

    

    NSData *passWordData = [userNamePassWordString dataUsingEncoding:NSUTF8StringEncoding]; // get NSData form NSString

    

    NSString *passWordString = [passWordData base64EncodedStringWithOptions:0]; // in http basic auth "Authorization" header accept encoded credential details

    

    NSString *basicAuthString = [NSString stringWithFormat:@"Basic %@",passWordString]; // "Authorization" header format i.e "Authorization" : Basic 123jkh43qe2erf= "

    

    [config setHTTPAdditionalHeaders:@{@"Authorization": basicAuthString,@"Accept":@"application/json"}]; // set headers on configuration

    NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; // create session

    

    // create data task for our "DELETE" request

  

    NSURLSessionDataTask *deleteTask =  [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

       

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;

        

        if (!error && httpResponse.statusCode == 204 ) {

            

            dispatch_async(dispatch_get_main_queue(), ^{ //multithreading

                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"204" message:[NSString stringWithFormat:@" node %@ deleted",nodeID] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

                [alert show];

            });

            

        }

    }];

    

    [deleteTask resume];

    

}

 Now try to reload page on your site it will say “page not found”.  You can also navigate to “admin” -> “reports” -> “dblog” to check log for the deletion we done.

Log for deletion

Now obviously we don’t want such application that we enter node ID to delete it. We can make a fairly sophisticated app from this one that has login screen to validate user first and than a UITableView to show list of all nodes on our site and then we delete them from app. But I just wanted to focus on how to use “DELETE” request and pass credential for basic authentication. At last I would like to mention that if you have older alpha versions than you may get “Dependency Injection Error https://drupal.org/node/2182055” .

I hope this would help you.

Tags:
Categories: Drupal
Syndicate content


Google+
about seo