// create object
$node = new stdClass();
// set title for a node
$node->title = t('Created node programmatically');
// set node type
$node->type = 'article';
// set node language
$node->language = LANGUAGE_NONE;
// set value to node body
$node->body[LANGUAGE_NONE]['value'] = t('This node has been created programmatically in Drupal 7');
// set value to node body summary
//$node->body[LANGUAGE_NONE]['summary'] = text_summary(t('This node has been created programmatically in Drupal 7'));
// set node body format like plain_text, filtered_html, full_html
$node->body[LANGUAGE_NONE]['format'] = 'filtered_html';
// author for a node
$node->uid = 1;
// status of node 0 - unpublished, 1 - published
$node->status = 1;
// promoted to front page or not
$node->promote = 0;
// sitcky at top of tha page
$node->sticky = 0;
// comments 0 - hidden, 1 - closed, 2 - opened
$node->comment = 1;
// add term
$node->field_tags[$node->language]['tid'] = 1;
// get the file path
$file_path = drupal_get_path('module', 'phponwebsites') . '/Desert.jpg';
// create file object
$file = (object) array(
'uid' => 1,
'uri' => $file_path,
'filemime' => file_get_mimetype($file_path),
'status' => 1,
// Save the file to the public directory. You can specify a subdirectory, for example, 'public://images'
$file = file_copy($file, 'public://');
// assign the file object into image field
$node->field_image[LANGUAGE_NONE] = (array)$file;
// Prepare node for a submit
$node = node_submit($node);
//save the node
After ran this code, you can see newly created node at admin/content. When you view that node, it looks like below image:
Now I’ve hope you know how to create a new node programmatically in Drupal 7.
Add new menu item into already created menu in Drupal 7
Add class into menu item in Drupal 7
Create menu tab programmatically in Drupal 7
Add custom fields to search api index in Drupal 7
Clear views cache when insert, update and delete a node in Drupal 7
Create a page without header and footer in Drupal 7
Login using both email and username in Drupal 7
Redirect users into any page after logged into a site in Drupal 7
You know how to get things done with git: pull, add, commit, push; but have you mastered it like a jedi does the force? Nothing is a more lasting record of our work then our git commits. In a galaxy where companies ask you for your Github account in lieu of, or in addition to a resume, we have one more reason to make sure that our commit history is as readable as our code itself.
In this one hour session, we will cover:
- Rewriting commits
- Reordering commits
- Combining commits
- The perfect commit message
- Finding bugs using git
- Avoiding common pitfalls
Join us for this session and you will leave a jedi-level git master!
These Are Not the Commits You're Looking ForRegister Now!
When we prepare to launch a site, we all generally follow a rough checklist of items (if only in our own minds!) to ensure sure that all systems are go. At Chromatic, we wanted to produce a repeatable process that we could share not only amongst ourselves, but also with the community; and so the Chromatic Site Launch Guide was born.
We are hosting this guide outside of our blog as it is a living document and will change over time. Feel free to bookmark it and refer back to it the next time you are preparing to launch a site. The content is generated from a repository on Github, which means modifications via pull requests are welcome!
Not long ago we were talking about the value of testing your updates in feature branch instances. It's the most efficient way of ensuring the quality of applied updates, but it's very time-consuming.
To use this process, you are required to maintain your own infrastructure to spin up QA servers quickly, run automated tests and share the testing instance between team members. And preferably, you do it every time an update is applied for any of the modules across your websites.Probo.CI integration QA Drop Guard recipes Drupal Planet
Recently I needed to migrate a small set of content into a Drupal 8 site from a JSON feed, and since documentation for this particular scenario is slightly thin, I decided I'd post the entire process here.
I was given a JSON feed available over the public URL http://www.example.com/api/products.json which looked something like:
Project kickoffs can be the shortest individual component of a project, but they can also be the most important. Done poorly, a kickoff can feel like a reading of a contract by inhuman actors doing inhuman work. Done well, a kickoff can bring a team together and push them towards success. Kickoffs are one of the project skills we don’t get many opportunities to iterate and learn. Developers at Lullabot commonly end up attached to a client or project for many months (or years!) at a time, so it’s entirely possible to go that period of time without having a formal kickoff. Here are some thoughts I’ve had after doing several kickoffs this year.About the Client
In a distributed team, a kickoff usually happens with a phone call. While pre-sales communication will have already happened, the kickoff call is usually the first time when everyone working on a team will be together at once. As a team member from the vendor, this is your chance to ask questions of the business stakeholders who might not be available day to day. I like to find out:
- Why are we all here? Are the business, technology, or creative concerns the primary driver?
- What is the business looking for their team to learn and accomplish?
- What are the external constraints on the project? Are there timelines and due dates, or other projects dependent on our work? What are the upcoming decisions and turning points in the business that could have a big affect on the project?
We all have ideas about how we want to work and be utilized on a project. Making sure they align with the client is very important to work out during a kickoff. Sometimes, a client has specific priorities of work to get done. Other times, they might not have realized you have skills in a specific subject area that they really need. It’s really important to understand your role on a project, especially if you have multiple skill sets. Perhaps you’re a great Drupal site builder, but what the client really needs is to use your skills to organize and clean up their content model. Figuring all of that out is a great kickoff topic.About Us
Once we understand each other, then we can start to figure out how we work together. It’s kind of like moving in with someone. You might know each other very well, but how are you going to handle talking with your landlord? How are each person’s work schedules going to integrate?
For a distributed team, communication tools are at the core of this discussion. We all have email, chat rooms, instant messaging, video, and more. What tools are best used when? Are there specific tools the client prefers, or tools that they can’t use because of their company’s network setup? Finding the middle ground between “all mediums, all the time” and “it’s all in person until you ask” is key.
Recurring meetings are another good topic to cover. Some companies will take new team members, add them to every recurring meeting, and use up a 10 hour-per-week consulting engagement with nothing but agile ceremony. Perhaps that’s what you’re needed for—or perhaps they’ve just operated out of habit. Finding a good balance will go a long way towards building a sustainable relationship.
Sharing each person’s timezones and availability also helps to keep expectations reasonable. Some companies have recurring meetings (like Lullabot’s Monday / Friday Team Calls) which will always be booked. Sometimes individuals have days their hours are different due to personal or family commitments. Identify the stakeholders who have the “worst” availability and give them extra flexibility in scheduling. Knowing all of this ahead of time will help prevent lots of back-and-forth over meeting times.
Finally, find out who you should go to if work is blocked. That might be a stakeholder or project manager on the client’s side, but it could also be one of your coworkers. Having someone identified to the team as the “unblocker of work” helps keep the project running smoothly and personal tensions low.About Tech
For development projects, the first question I ask is “will we need any sort of VPN access?”. VPN access is almost always a pain to get set up—many companies aren’t able to smoothly setup contractors who are entirely remote. It’s not unheard of for VPN access to take days or weeks to set up. If critical resources are behind a VPN, it’s a good idea to start setting that up before an official kickoff.
Barring the VPN-monster, figuring out where code repositories are, where tickets are managed, and how development and QA servers work are all good kickoff topics. Get your accounts created and make sure they all work. If a client is missing anything (like a good QA environment or ticket system), this is when you can make some recommendations.About Onsites
Some projects will have a kickoff colocated somewhere, either at a client’s office or at a location central to everyone. In distributed teams, an in-person meeting can be incredibly useful in understanding each person. The subtle, dry humour of your video expert becomes apparent in-person, but could have been misunderstood online. Most of the above can be handled in the first hour of an onsite visit, leaving much more time to fill given the travel time!
We like to focus onsites on the topics that are significant unknowns, require a significant number of people across many teams, and are likely to require whiteboards, diagrams, and group brainstorming. Project discoveries are a classic fit; it’s common to meet with many different people from different departments, and doing first meetings in person can be a significant time saver. The goal of an onsite shouldn’t be to “kick off” the project—it should be to build the shared understanding a team needs so they can be effective.But what about sales engineering?
I’m sure some readers are now thinking “Wait a minute! Aren’t these all things you should know before a contract is signed?”. It’s true! Going into a kickoff without any of this information would be a serious risk.
It’s important to remember that the team on a kickoff isn’t going to be identical to the team who did the sales engineering work. Both the client and the vendor will have new people just getting started. As well, it’s useful to hear the project parameters one more time. Discrepancies in the discussions can alert the team to any misunderstandings, or more likely changes in the business environment running up to the signing of the contract. Especially on projects where a team is already working, hearing about progress or changes made in the week between signing an SOW and kickoff can be invaluable.
What did you learn the last time you helped to kick off a project? Let us know in the comments!
Drupal 8 has lots of things that Drupal 7 doesn't have - a modern object-oriented foundation, the Twig templating system, and WYSIWYG out-of-the-box - just to name a few. There's also a good number of less flashy additions that are designed to improve the developer experience. One of these additions is the /core/rebuild.php file.
While it is common knowledge that clearing rebuilding Drupal's caches is good practice during development, Drupal 8 brings a new tool to the table to get it done. Previous to Drupal 8, most developers utilized Drush to clear caches, some less-efficient folks cleared caches from the user interface (usually from the Admin Menu, but sometimes - gasp! - from the admin/config/development/performance page).
Drupal 8 comes with a new /core/rebuild.php file that doesn't require the Drupal 8 site to be functioning (fatal errors, anyone?) nor does it require Drush or Drupal Console. Instead, as long as your site's configuration allows it, all you have to do is navigate to /core/rebuild.php in your browser. As Drupal's documentation states, this "Rebuilds all Drupal caches even when Drupal itself does not work."
How do you know if your site's configuration supports this functionality? Well, if you're working locally (and if you're developing, you should be working locally), then just make sure that $settings['rebuild_access'] = TRUE; in your settings.php (or, better yet, settings.local.php). The other method involves running the /core/scripts/rebuild_token_calculator.sh script from the commandline, and using the results as query parameters for /core/rebuild.php (see "Method II" on https://www.drupal.org/node/2153725).
Granted, most developers have Drush and/or Drupal Console installed everywhere they're working, but it's always good to have a backup method for rebuilding Drupal's caches - just in case.
DrupalCon New Orleans is nearly here and Chromatic will be attending in full force! Here's the rundown of what you need to know:Learn About Render Arrays from Gus Childs
Gus will be presenting his session on Drupal 8 render arrays on Tuesday at 1pm in the Blackmesh Room (267-268): Aha! Understanding and Using Render Arrays in Drupal 8. If you're ever been confused by render arrays or just want to learn the best practices for how you're supposed to use them, be sure not to miss this session. Gus happens to be an awesome presenter to boot!Schedule or Attend a BoF in the Chromatic Room
We're once again sponsoring a Birds of a Feather room. BoFs are a great way for folks to get together and discuss interesting topics in a more informal setting. There's already some great BoFs scheduled for the Chromatic room, including one on Drupal VM and Local Development from the well-known geerlingguy. We have a couple BoFs of our own too:
If you have a great idea for a BoF, schedule one for the Chromatic room!Connect with Us at one of the Summits
Every year, DrupalCon attendees rave about how awesome and comfortable our t-shirts are. That's because we don't believe in making swag that we ourselves wouldn't love to wear. This year is no different. For NOLA, we've made a limited run of some special vintage baseball tees, printed on 3/4 sleeve American Apparel 50/50 cotton. These shirts are our best yet and we want to give you one for FREE!
See you in New Orleans!
Devising an effective inbound marketing strategy is vital for countless reasons, and is critical for the growth of business in terms of gaining exposure, building your brand, and truly 'connecting' with prospective leads and customers, members of your industry's target audience.
There are countless reasons this type of marketing is so essential to your success on the Internet, including:
Navigating through Drupal's admina area can be complex for users.
Drupal's Coffee Module can help Drupal newcomers. Coffee adds an additional search function which allows admins to search and go directly to the areas they need.
Coffee is available for both Drupal 7 and Drupal 8.
As of this writing the only site building readily available module is the PLUpload file widget.
This module depends on the PLUpload form element provided by the Plupload integration module, that is a more developer oriented module.
With the Plupload widget/integration you can:More articles...
- Exposing reverse entity reference fields in Drupal
- Drupal 8 Couchbase Integration
- PDF Generation in PHP
- Drupal on IIS or Apache
- Benchmarking Drupal 7 on PHP 7-dev
- How to use NetPhp
- Drupal 8 Wincache Integration
- Benchmarking Drupal 8 on PHP 7-dev
- Fixing slow queries and database deadlocks in Drupal without PHP profiling tools
- Drupal 8 Performance: Moving the service container cache away from the database
Over the past month, I've been attempting to learn more about Drupal 8 by attempting to port the @font-your-face module which has a lot of different pieces; it touches on Content Entities, Config Entities, regular entities, views, classes, hooks, and more! I'll try and blog on my experiences with that in the near future but an interesting problem that I ran into is that I am using taxonomy terms to categorize Font Classifications, supported languages/subsets, and generic tags.planet drupal
typey has just turned 1.0, so I thought it would be a great time to show off some of its features.
On April 20, five months after the launch of Drupal 8.0.0, we released Drupal 8.1.0, the first scheduled minor update. Drupal 8.1.0 comes with both new features and bug fixes that were not eligible for monthly patch releases. Now is a great time to try Drupal 8 if you haven't yet!
Drupal 8.1.0 is production-ready, but (like most software) still has known bugs that can cause issues for some modules or sites. Although we fixed hundreds of critical bugs during Drupal 8's development, and although only a handful of critical issues have been discovered since Drupal 8.0.0, there are still hundreds of less severe bug reports marked with "major" priority.
500 major bugs
Major issue triage sprint at DrupalCon Asia 2016. Photo credit: Amazee Labs.
500 major bugs sounds like a lot, right? Many of these bug reports are still relevant and important to fix for Drupal 8 to be more robust. However, many other reports are outdated; they might already have been resolved, they might no longer be relevant, or they might be misfiled. As many Drupal contributors know, it can be hard to find the right issues.Find the issues that matter
Finding (and fixing) the bugs that are most important is a group effort. We use a two-phase process:
- Contributors verify the current status of the major issues, make sure they are up to date, and close issues that are no longer relevant.
- Core committers and subsystem maintainers collaborate to assess the verified issues.
We call this process "issue triage". And phase 1 is where you come in! Help us sort through these major bug reports at DrupalCon New Orleans. This flowchart illustrates the workflow we will use at the major issue triage sprint:
(You can also read the detailed instructions in the major triage meta issue.)
Once the current state of these bug reports is verified, Drupal 8 core committers and subsystem maintainers will prioritize them, deciding which are indeed major, which are just normal bugs, and even which ones are critical issues in disguise.Reasons to come to the major triage sprint
- Help squash bugs faster, so that Drupal 8 is even better for your next Drupal site.
- Become more familiar with Drupal 8 (and the kinds of bugs that still need fixing).
- Improve your git skills and learn git techniques that will help you in your own projects.
- Learn about how issues get solved in Drupal core and how to contribute effectively.
- Get to know a particular subsystem of Drupal 8 in more depth.
- Get credit on your Drupal.org profile when the issues you verify are eventually fixed.
- Collaborate with the amazing maintainers who've brought you Drupal 8.0.0, Drupal 8.1.0, and each bugfix release.
Sounds awesome, right? You can sign up on the DrupalCon New Orleans sprint sheet under "Bugs-- // Drupal 8 criticals and majors". Longtime core mentors cilefen and valthebald will be helping lead the major triage. (New to Drupal contribution? Join the First-Time Sprinter Workshop.)
xjm Tue, 04/26/2016 - 22:57
Drupal core is pretty well optimized. But after you've finished building your Drupal 7 or 8 site, you might find some pages are loading slower than you'd like. That's not surprising—you've probably enabled scores of contrib modules, written custom code, and are running over 100 SQL queries per uncached request.read more
If you are working on a website redesign, 404s are the very real monsters under your bed. Ignore them, and they will wreak havoc on your website’s traffic. Worst of all, by the time you realize what’s happening it may already be too late.What are 404s?
Very simply, 404s are broken links. More specifically, 404 is the HTTP response code for “Not Found,” signifying that a web page is not available at the provided URL. Reorganizing old content, changing old URLs and selectively discarding content that is no longer relevant are all common activities during website redesign projects that can result in 404s.Why 404s Are so Bad
Your legacy content – the stuff that’s been around for 15 years, from the most up-to-date research articles, to blog posts written by employees long-gone, to PDF files in random folders off your webroot – has been quietly growing your website traffic, catching inbound links and increasing effectiveness of organic search. And the longer it has been around, the more valuable it has likely become, even if the content itself is no longer of much relevance to your organization. A quick scan of your Google Analytics will likely confirm this. Your organic search traffic probably has a very long tail: thousands or tens of thousands of pages with a few hits each, funneling users to your website.
If those URLs change, or that content is abandoned entirely, the potentially massive net you have been casting – and growing – for years will be damaged. Despite the very best user experience, the most on-target messaging and the most compelling design, years of search engine optimization (SEO) progress can be lost – all because of 404s. Your organic search rank will drop as search engines remove the now-broken URLs from their indexes. As a result, traffic will plummet. All of this can very quickly bring the success of your entire redesign project into question.
In website redesigns, 404s may very well be your worst enemy.Combatting 404s Starts with Content Strategy
Dealing with 404s is an important, often overlooked component of effective content strategy. Communications teams frequently devote significant time to performing content audits, flagging content to be be reorganized, rewritten or abandoned altogether. Far less time – if any – is given to thinking through exactly what to do with content that is left behind. It is simply abandoned. Soon after launch, someone in marketing notices a drop in traffic and suddenly 404s are on everyone’s radar.By Default, Keep Everything
When redesigning a website, we recommend keeping just about everything. That might be opposite of what you’ve heard before. It doesn’t lend itself to the “cleaning out the garage” or “moving to a new house” metaphors. In reality, though, your legacy content is one of your greatest assets. That junk in the garage is gold. Deal with it, but don’t abandon it.
For outdated content, channel users to more relevant offerings with good user experience design and carefully crafted messaging. Old content – even if outdated – represents an opportunity to connect with users you otherwise might miss entirely, communicating key changes in your organization or pointing to relevant, up-to-date resources. Again, dealing with legacy content is an important element of content strategy. It deserves design attention and good user experience. Craft a simple message that says “This resource is out of date. To see our more recent work in this area, see X, Y or Z.”
For content that is rewritten or moved to a new URL, use 301 redirects to redirect users automatically from old pages to their new equivalents. 301 redirects, or 301s, signal to search engines that a resource has not been eliminated; rather, it has been “Moved Permanently” and should be reindexed at its new location. 301s are hands-down the most important technical device for dealing with 404s.
(Note that 301s do not guarantee that your content will maintain its rank within search results. Rather, 301s indicate to search engines that the resource for a particular URL has been moved. Search engines will queue the new URL for reindexing, and search rank will once again be determined by a broad spectrum of factors like keyword density, page title, inbound links, etc.)Add 301 Redirects for All Migrated Content
When migrating legacy content into your redesigned website, add a 301 redirect for every single resource, article or page being migrated. As of right now in Drupal 7, a patch for the redirect module makes this process easy: simply map the old URL to the special destination field “migrate_redirects” and the redirect module will take care of the rest.
In Drupal 8, the redirect module provides built-in support for migrating redirects from older versions of the Content Management System. A little bit of custom code in your scripted migration can take care of adding redirects for migrated nodes. (Need more info? Let us know in the comments or get in touch.)Find and Prioritize All Legacy URLs
While adding 301 redirects for every migrated page is critical, it is not enough. Google has likely indexed large numbers of URLs for content that will not be included in your scripted migration process. Landing pages, listing pages, PDFs and anything you have specifically decided not to migrate will be omitted if your focus is solely on individual articles. To better understand the full scope of URLs that need to be dealt with, download a report of all pages from Google Analytics or whatever analytics platform you are using. This not only provides a thorough catalog of web pages, PDFs and other resources being viewed, but also shows a count of monthly page views and is incredibly helpful for establishing priority for specific pages to be redirected. Remember, your traffic has a long tail; the potentially thousands of pages that receive one or two views per month are still important.Test All Legacy URLs In Your Redesigned Website
Once you have a list of all legacy URLs you need to test your new, redesigned website to see which URLs are resulting in “404 Not Found” errors. We have a few custom scripts that do exactly that, written in environments ranging from Drupal modules to standalone NodeJS apps. Regardless of the specific implementation, the script needs to do the following:
- Import a list of legacy URLs downloaded from your analytics service.
- Loop through the list of URLs and test each on the new website to see what HTTP status code is returned.
- If a 301, 302 or other redirect is returned, follow it to ensure it eventually results in a URL with an acceptable status (200 OK).
- Generate a report of returned status codes. We typically include page views from the originally downloaded analytics report in this CSV so we can see the status code directly beside the number of monthly views for each URL. Seeing the HTTP status code, URL and number of pageviews all side-by-side in spreadsheet format is incredibly helpful for gauging priority.
The first time you run your script, you will likely see a very high volume of 404s. That’s fantastic: you’re seeing them now, during the redesign, before they are anywhere close to impacting SEO or traffic.Fix the 404s
Your report of returned status codes provides a prioritized list of 404s that need to be dealt with. You will likely see a mix of landing pages, listing pages, articles, PDF files and other resources. Each URL needs to be dealt with.
Often, large numbers of similar URLs can be redirected programmatically – that is, by matching patterns rather than specific addresses. For example, a collection of folders containing PDFs may have been moved to new locations. Or URLs for pages that show content by category may need to be mapped to new category ids. Depending on the complexity of the specific redirect pattern and the environment in which your website is hosted, programmatic redirects can be added to Drupal in a variety of ways, as follows:
- Using mod_rewrite in your .htaccess file
- The match redirect module for Drupal 7
- A custom module using hook_init()
- Custom code in settings.php
If your legacy URLs are directory indexes (i.e. ending with “index.html” or “index.htm”) you will need to add an additional redirect for the version that does not include the file name.
Example: if your legacy URL is “http://example.com/path/to/file/index.html” and the new equivalent is “http://example.com/new/path/to/file”, you will need two redirects:
- One from “http://example.com/path/to/file/index.html” to the new URL
- Another form “http://example.com/path/to/file” (without index.html) to the new URL
We typically add additional redirects for directory indexes once all other redirect work is finished, using a simple custom script that scans the redirects table for index pages and generates the appropriate equivalent.Test Again, Rinse and Repeat
Once all 404s have been dealt with in the ways outlined above, test your redesigned website again. You will likely find a few URLs that still need to be addressed. Rinse and repeat until the entire list of prioritized pages returns the acceptable status code of 200.Not Quite Done
And that’s it. Almost. The final piece to combatting 404s is to monitor them closely after launch. The redirect module provides a simple admin page for doing exactly that. We strongly recommend monitoring 404s for several days after launch and adding 301s wherever appropriate.Sit Back and Relax
Website redesign projects usually impact organizations at all levels, and we know you probably won’t be able to truly sit back and relax after launch. There will be final communications details, stakeholder reviews, content updates, ongoing bug fixes and likely a growing list of next-phase wishlist items. That said, dealing with 404s will help protect your investment in organic search and mitigate deleterious effects on web site traffic. There will still be a dip in the numbers as Google and other search engines update their indexes and re-crawl new content. This post doesn’t address SEO strategy in-depth, nor setting specific traffic goals and benchmarks as a part of planning and discovery for your website redesign. It does express the very clear need to accommodate modified URLs and abandoned pages. Without an effective redirect strategy, 404s will almost certainly wreak havoc on your organic search traffic. Good content strategy and 301 redirects are critical allies for fighting 404s and protecting your years-long investment in SEO.
This DrupalCon we're cranking up the community exposure in the exhibit hall.
One of our OSTraining members asked about changing JQuery, so we created this tutorial for him.
Below is quick guide to installing Drupal's Jquery plugin module.
Each day, more Drupal 7 modules are being migrated over to Drupal 8 and new ones are being created for the Drupal community’s latest major release. In this series, the Acquia Developer Center is profiling some of the most most prominent, useful modules, projects, and tools available for Drupal 8. This week an interesting mobile-usability helper: Responsive and off-canvas menu.Tags: acquia drupal planetMotWdrupal 8D8UXmobilemenu
Acquia Developer Center Blog: 3 Media Challenges in Drupal, and How to Use the Media Module to Vanquish Them
Drupal 7 out the box offers a good implementation for uploading media, but it has three significant challenges.Challenge 1: Files should be entities
In Drupal, files should be entities so you can add additional fields to the file type. As an example, when you upload an image you will want your standard image alt attribute, which specifies alternate text for an image, if the image cannot be displayed, or the user is using a screen reader. But you may want to have additional fields, such as photo credit or image caption.Tags: acquia drupal planet