Вы находитесь на странице: 1из 688

^

Benjamin Melancon, Allie Micka, Amye Scavarda and others

The Definitive Guide


to Drupal 7
Benjamin Melancon, Jacine Luisi, Karoly Negyesi, Greg Anderson, Bojhan Somers.
Stephane Corlosquet, Stefan Freudenberg, Michelle Lauer, Ed Carlevale, Florian Loretan,
Dani Nordin, Ryan Szrama, Susan Stewart, Jake Strawn, Brian Travis, Dan Hakimzaaeh,
Amye Scavarda, Albert Albala, Allie Micka, Robert Douglass, Robin Monks,
Roy Scholten, Peter Wolanin, Kay VanValkenburgh, Greg Stout, Kasey Qynn Dolin,
Mike Gifford, Claudina Sarahe, Sam Boyer, and Forest Mars, with contributions
from George Cassie, Mike Ryan, Nathaniel Catchpole, and Dmitri Gaskin

Apress*

Drupal

Drupal 7
. , . , , . , . , . ,
. , . , . , . , . , . ,
. , . , . , . , . , . ,
. , . , , , . , ,
. , . . , . , . , . , . ,
. , . , . , .

^ *
-
-- -

2013

32.988.02-018
004.738.5
84

., ., . .
84

Drupal 7. .: , 2013. 688 .:

.
ISBN 978-5-4461-0054-5

CMS Drupal 7,
Drupal. ,
, 7- , ,
Drupal. ,
() ,
Drupal, - CMS,
, , Drupal.
,
, Drupal, ,
.

32.988.02-018
004.738.5

Apress. .
.
, , ,
. , ,

, .

ISBN 978-1430231356 .

aPress, 2011

ISBN 978-5-4461 -0054-5 , 2013


, , 2013

................................................................................................ 17
I.
1. Drupal 7 ...................................... 34
2. : Drush G it......................................... 56
II.
3.
Views..................................................... .70
4. ...................................................104
5. Organic Groups .............................................................122
6. Drupal.............................................................. 135
7. Drupal.....................................................................146
8. .....................................................................156
III.
9. Drupal- ......... .......................................................192
10. .................................................. 200
11.
....................................................................... 216
12. .................................................................. 222
13. .. 237
14. ............................................................... 253

IV.
15. .........................................................................................258
16. .............................294
V.
17. ..........................................334
18. API .......................................357
19. ..................................................................406
20. Drupal 7................................................426
21. ...........................440
22.
Simpletest......................... .........454
23. ....................... ........................468
VI.
24. Drupal Commerce........................................................498
25. Drush....................................................................526
26. Drupal......................................................564
27. Drupal................................................ 581
28. Drupal.......................595
29. Apache Solr Search Integration.....................608
30. : 90 % ....................... ....... 620
31. Drupal ............673

..................................................................................................17
Drupal?.......................................................................................................17
Drupal 7 ..................................................................................................... 20
............................................................................................25
Drupal....................................................................................28

I.
1. Drupal 7 ................................. 34
: ...........................................34
.............................................................................................................38
................................................................................ 43
...................................................................................................... 55

2. : Drush Git.....................................56
Drush......................................................................... 57
Git: ................................................................................ 62
............................................................................. 67
...................................................... ......................................................67

II.
3.
Views.............................................................................70
Views?..................................................................................................... 70
............................................................................ 73
................................................................................... 76
....................................................................86
................................................................................ 94
........................................98
..................................................................................................... 101
........................................................................................................ 101
..................................................................................103

4. .......................................... 104
Drupal-...................................................104
, ......................................................................104
........................................................................................ 105
- ............................................................................107
.......................................................................................................... 107
.................................................................................... 110
....................................................................................... 110
.................................................................................... 114
............................................................................................... 121

5. Organic Groups...................................................... 122


Organic Groups................................ 122
Views Organic Modules ................................ 126
...........................................................................128
Panels......................................................................130
, .............................................................................. 133
............................. ............................................................................. 134

6. Drupal ...................................................... 135


Drupal................................................135
............................................................................... 138
........................................................................................................... 145

7. Drupal............................................................. 146
.................................................................................... 146
........................................................................................................... 147
........................................................................................148
Drush............................................................................ 150
diff...............................................................151
............................................................................................152
Drush......................................................... 154
............................................................................................................155

8. ............................................................. 156
........................................................................ 156
...................................................... ............................................163

........................................................................168
........................................................................................... 171
...................................................................179
Resource........................................................................................ 180
........................................................ 182
, ............................. 185
Status.................................................................. 187
URL- Pathauto............ ......................189
......................................................................................................... 190

III.
9. Drupal-............................................................. 192
...................................................... 193
...............................................................................................193
........................................................................................................... 198

10. .......................................... 200


.................................................................................................200
................................................................................................. 201
............................................................... 204
.................................................................................... 206
................................... 209
............................................................... 212
.................................................................................. 215

11.
.................................................................216
?............................................................... 216
.........................................................216
...................................................217
.................................................................... 218
.....................................................220
......................................................................... 221
............................................................................................................221

12. ............................................................. 222


Quickstart.................................................................................222
.........................................................................224

10

.................................................................................228
...........................................................................................................236

13.
..........................................................237
.....................................................................................237
.....................................................................................242
....................................................................244
...........................................................................................................252

14. .........................................................253
................................................................................................. 253
.....................................................................................253
.......................................................................................254
............................................................................................. 255

IV.
15. ....................................................... .............................258
.....................................................................................258
.....................................................................................262
................................................................................................ 265
............................................................................................. 269
................................................................................................. 279
..........................................................................................................286
.......................................................................... 289
........................................................................................................... 293

16. ................... 294


.................................................................. 294
......................................... 296
Render API.............................................................................................................. 303
render(), hide() show()....................................................................... 308
.....................................................................................310
CSS-...........................................................................................................320
..................................................................................326
............................................... 329
........................................................................................................... 332

i i

V.
17. ................................... 334
............................................. .......................................... 334
.............................................................................................347
...........................................................................................................356

18. API ..............................357


........................................................................................357
t() format_plural()..................................360
........................................................................................ 361
hook_menu() ......................................368
............................ 373
377
.............................................................................. 378
........................ 379
............................................................ 381
Drupal .................................................. 383
: CSS-....................... ........................385
API .................................................................................................... 387
................. ........................................400
........................................................................................404
...........................................................................................................405

19. ............................................................ 406


............................................406
........................................................................... 412
................................................................................ 414
...........................................418
..............................................................................................419
.......................................................................................................... 425

20. Drupal 7 .......................................426


................................................................................. 426
...................................................................................... 429
Drupal.org........................................................ 438

12

21. ..................440
....................................................................................... 440
........................................................................................................................ 441
.....................................................................................................................442
.....................................................................445
jQuery U I............................................................................................448
................................................... 449
........................................................................................................... 453

22.
Simpletest.......................... 454
Simpletest....................................................................................... 455
Simpletest................................................................. 455
................................................................. 456
Simpletest....................................................................................... 456
.................................................................................... 457
.test........................... ............................................................... 458
............................................................................462
Simpletests ........................................................................................... 464
API Simpletest ...................................................... 465
Drupal.org ................................................466
........................................................................................................... 467

23. .......................................... 468


............................................................................469
Drupal-........................................................... 470
API?..................................................... 471
.........................................................................472
....................................................................... 474
.....................................................................................................476
........................................................................................ 482
........................................................................................... 484
.............................................. 490
.....................................................................493
............................................................................................495

13

VI.
24. Drupal Commerce................................................. 498
Drupal Commerce .....................................................................498
...............................................................498
Drupal Commerce....................................................................... 499
Drupal Commerce........................................................................... 517
........................................................................................... 518
Drupal 7 ..........................................................................................520
...........................................................................................................525

25. Drush............................................................. 526


Drush........................................................................................527
Drush ...............................................................533
Drush..................................................................... 536
Drush ......................................... 538
Drush ..................................................... 540
Drush....................................................................... 547
Drush........................................................................................ 556
...........................................................................................................563

26. Drupal............................................... 564


?.................................................. 564
......................................................................................................................... 565
memcached .....................................................................................567
Varnish.............................................................................................. 568
........................................................... ..............................................568
MongoDB........................................................................................575
................................................................. ...................................... 580

27. Drupal........................................ 581


Drupal ...................................................................581
........................................................................... 585
..........................................................................................590
..................................................... 592
...........................................................................................................594

14

28. D rupal............ 595


............................................................................................................... 595
.................................................................................601
.......................................................................................................... 607

29. Apache Solr Search Integration...........608


API Search................................................................................................612
Apache Solr Search..............................................614
Apache Solr Search............................................................. 616
Apache Solr.................................................................618
.......................................................................................................... 619

30. : 90 % .......................... 620


.....................................................................620
.....................................................................................623
..................................................... 626
Drupal.org Twitter
.................................................................................... 629
C S S .................................. 637
Add New .........................................638
.................................................. 642
Next Previous, ........................... 665
URL-........................ 671
........................................................................................................... 671

31. Drupal .. 673


................................................................................................. 673
..................................................................675
: Features.................................................... 680
........................................................................................... 685
................................................................................................... 686
...........................................................................................................687

Drupal- ...

Drupal .
, ,
.
.
Drupal , .

.
,
.
Drupal
j Query, .
Drupal, ,
, ,
. Drupal
, Git,
. ,
Drupal; , ,
.
,
Drupal-. ,
, Drupal 7,
. !
(webchick),
Drupal 7


Drupal?

Drupal ,
- . ,
, , ,
, ,
, ,
, , ,
.

. 1 . Drupal-

CMS
, Drupal... !
43folders.com

Drupal
(Content Management System, CMS):
; ; ;
, , ;
. ,
.
Views ( 3)
. Groups (
5) .
Drupal Commerce ( 24)
-. Drupal,
( 4).

18

Drupal ,
(. 15 16), ( 25)
( 29), , -
.
( 17 23)
. ( 9 ,
Drupal, .)
Drupal JavaScript
( JQuery),
, MariaDB/MySQL
PostgreSQL. ,
, Drupal, . ? Drupal
,
. .
Drupal ,
.
,

. [...] ,
, , CMS.

. , ,
,
Drupal.

Drupal
, Drupal , .

Drupal ,
, , CMS:
-.
(Application Programming Interface, API)
, Drupal CMS.
Drupal ,
Facebook - (nysenate.gov/mobile, data.gov.
uk, zagat.com), (buzzr.com). Drupal
CMS ,
Java Flash AJAX.
CMS
Drupal-, .
Open Atrium (openatrium.com) ,
Drupal Commons (drupalcommons.com) , OpenPublish (openpublishapp.
com) OpenScholar (scholar.harvard.edu)
. ( ,
, 31.)

Drupal?

19

Drupal
,
, .
-

,
- .

.
,
, .
Drupal, Drupal (Resource
Description Framework, RDF).
RDF ,
,
. Drupal ,
, ,
,

.

Drupal
Drupal ,
, , , . (, ,
, .)
Drupal
.

, Drupal. ,
, . ,
Drupal Drupal
.

, Drupal,
, .
.
Drupal Drupal Con
- 2010 :
, , .
, Drupal-
.
?
, .
101, , .
, Drupal, ,
.

20

Drupalcon? .
.
Drupal?
, Acquia.
, :
! Drupal Gardens! Drupal! Dries!
. .
Drupal ,
, , , , . ,
Drupal-.
Drupal ...
... ,
(buytaert.net).
... (webchick.net),
Drupal 7 ,
, ,
.
... , , -, ,
, , , , ,
Drupal (drupalcon.org).
... , 145- , CMS,
, (thenation.com).
... 35 (scottbrown.com).
... - (starswithstripes.org).
... (sba.gov, whitehouse.gov ).
... - (libcom.org).
... 50 ,
(teslamotors.com).,
... (lxDA.org).
... (robinwilliams.com chrisrock.com).
... (examiner.com)
(, bolivia.indymedia.org tc.indymedia.org).
... ,
Drupal 7 (drupalgardens.com).
... , Drupal,
(angrydonuts.com), (
, ), (angrylittletree.com)
Drupal ,
(palantetech.com).
Drupal. . Drupal .
D ru p a l 7

, Drupal ;
. , Drupal 6

21

Drupal 7

, a Drupal 7
. .

, ,
Drupal, , .
Drupal-
.



, ,
(. 2).
.
,
. .
.
Dashboard
Add content

Content

Find content

Structure
Bartik settings

Appearance
Menus

People

Modules

Management menu

Configuration

Add user

Reports

Kelp

Hello 007

Blocks

Log out
Edit shortcuts

Definitive Guide to Drupal 7


Wht8'& New in Drupal

"iffinmistrat

Edit view
Configure block

Toolbar
Shortcut toolbar

Contextual links
Contextual links provide one-click navigation to content editing screens.
They also help Drupal newcomers figure that this content was created in
orthat content is a block, a menu, etc.

Toolbar
Adimnistrative toolbar provides quick access key functionality, \ Delete
improved grouping of functionalityie, a direct link to the Modules
ipage.

. 2 . Drupal 7,
(1), (2) (3)

.
. . + () - ()
, ,
. (, Blocks)
( , ).

22

, , ,
, . .
.
, ,
, .
.
. ,
Drupal, ,
.
,
. Drupal 7 ,
Drupal .
Drupal ,
. Dashboard
,
, , /
Drupal (. 3).
A

Dashboard

Add content

Content

Find content

Structure
S2

Appearance

People

Modules

Configuration

Reports

Hello 007

Help

Site Administrator

i og out
Edit shortcuts

Home * Adrrtimstration

Dashboard
Custom ize dashboard

Recent content

Who's new

Duis Metuo Quia Torqueo new


,

edit

delete

Antehabeo Ittum Vento -new

edit

detete

Anonymous (not verified)

Anonymous {not verified)

00 ?

Most recent poll


(empty)
Mora

Recent blog posts


* Acsi GHvus incassuro
imputo Obruo
Nunc Pec us Proprius
ju s Nobis Paratus

* u tudus iuptaturn Nunc


More ;

. 3 . Dashboard
,
,


Drupal 7 ,
, , .
.

.

23

Drupal 7

Drupal 7.
.
D7CX, ,
Drupal , .
Drupal 7 , MariaDB 5.1.44 ,
MySQL 5.0.15 , PostgreSQL 8.3 SQLite 3.x.
.


Drupal 7 , ,
, JavaScript CSS,
. Drupal 7
5.2.4 .
-.

7
, Drupal 7
.

Drupal 7 .
, (. 4).
,
.
Modules
I

*>

Home * Administration Modules

You can find

m o d u le s

and

th e m e s

I
on

d ru p a f.o rg .

The following file extensions are supported: tar tgz gz bz2 .

Install from a URL


|httpyynp.cK-upalcK-^fHes/projects/ctoots-?.*-1.0-atpba2.tar. \
For exam ple; http://ftp.drupai.org/files/projects/name.tar.gz

Or
Upload a module or theme archive to install
( Choose R ie J No chosen
For exam ple: n a m e . m g z from your local computer

Install

. 4 . Drupal


Drupal , :
- Bartik. Drupal 7,
, CSS- (. 5).

24

Home | Guidne

Etiam est risus

Lorem ipsum dolor

Maecenas id porttitor Ut
enim ad minim veniam,
quis nostradfeiis. Laboris
nisi ut aliquip ex ea.

Sit amet, consectetur adipisidng elit, sed do eiusmod


tempo r mddidunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exerdtation uOamco
laboris nisi ut aliquip ex ea commodo consequat. Maecenas
id porttitor Ut enim ad minim veniam, quis nostr udfelis.


ET IA M

vsv tusus

MasoffiBis id 'porttitor Ut enim ad


m inim veniam, quis uostrudfebs.
Labor* nisi ut aiiquip e*.

Dotsec placerst
Nuibwn nsbh defer
land it sed
Ferm estum id

. 5. Drupal 7 Bartik

, .
,
. ,
, .
, -
, . 6. Bartik 15
. Seven ,
.

Seven.

Stark.

. 6. Bartik Seven


Drupal 7 .
,

25


.
, ,
.
, ,
.
RDFa
RDFa HTML ,
,
. ,
.
RDFa w3.org/TR/xhtml-rdfa-scenarios/.

Drupal 7 , ,
:
(
).
cron.php (
, , example.com/
cron.php, , , ).
, .
Filter .
FileField.
Test ( Simpletest)
Drupal. .
22.
, Drupal 7.
drupal.org/about/new-in-drupal-7 drupal.org/drupal7 -released.


: 106 ,
, , , .
: .
, 1980

Drupal 7!
, Drupal,
Drupal 7 . ,
Drupal , .
: , ,
.
Drupal, :
,
.

26

Drupal-.
.
, Drupal.
Drupal-
.

Drupal? !
, 1 Drupal . ,
.
9.

?
, , Drupal
.
. Drupal ,
Drupal-.

Drupal .
, ,
.
Drupal ,
, ,
Drupal. :
, ,
, , . ., ,
.

, , Drupal.
, , ,
.
.
Drupal . ,
. ,
. ,
Drupal .
, ,
.
Drupal-.
Drupal,
, .
, Drupal 7
.
,
.

Drupal :

27

;
.

, -, ,
VirtualBox Drupal, drupal.
org/project/quickstart. ,
Drupal, 12.


,
. .
, .
Drupal .

. ,
.
, .
Drupal.
, .
- , .
,
, .
,
.
, , ,
. ,

. , - ,
9, .


Drupal 7
. (?
, -.)
,
Drupal. ,
, Drupal. .
, , (user).
Drupal 7 (people), ,
, ,
, ,
.
Drupal (node).
? ,
;
( , , ).
,
. , , ,

28

, . ,
, ,
, Drupal.
,
. ,
(definitivedrupal.org/forums dgd7.org/fora). ,
( ).


URL/ ( Drupal, ,
admin/content). , , ,

, : Administer Help (admin/help).
URL-
( example.com URL- http://example.com/admin/people/
permissions/roles ).
,
, Drupal.

definitivedrupal.org (
dgd7.org). dgd7.org/code.
,
. , .
, ,
.
Drupal, ,
.
9.
,
. Drupal
, Drupal .
, .
dgd7.org/updates , ,
.
news@definitivedrupal.org.
~
Drupal ( ;
; ), ,
Drupal-.

Drupal

Drupal, .
, Drupal,
.

Drupal

29

Drupal
Drupal, WordPress (wordpress.org) Expression Engine (expressionengine.com),
(Content Management System, CMS). Drupal
,
.
Drupal
Drupal .
, (5 .,
10 . . .). ,
, , . (views)
; (pages) (blocks)
, , .
(themes) (modules) ;
, , (. 7).

. 7 . Drupal

Drupal :
. WordPress,
, Drupal
,
. , .
, ,
Drupal
. #Drupal,
, .
9.

,
(node) . ,
, , . ,
, .
, .
(field) Drupal.
,
(, ), .
(block) ,
( , ).
(. ) Blocks.
. ,

30

,
.
(content type) .
Drupal ,
.
(taxonomy) .
(, ),

. ,
(, . .), ( ),
(, , . .).

.
(users), (roles) (permissions).
, , .
. Drupal
, ,
, . ,
author (),
, ,
. editor ()
.
(module) , .
Drupal ,

. drupal.org/project/modules.
. Drupal
Views, Pathauto Token. URL .
3 8, , .
(view) ,
Views. 3.
(theme) , . Drupal ,
.
sites/all/themes,
.
tpl.php -, Drupal .
Drupal, , , , tpl.php.
,
, .
Drupal (D r u p a l C o re ) Drupal-npoeK Ta ,
Drupal.org. ,
/sites.
, , 15 16.

Drupal-npoeicra

Drupal
,

Drupal

31

.
Drupal ,
,
, .
Drupal.
10.
1.

, .
, , ,
.
;
, .
,
.
, Drupal,
- .
:
? ?
?
( ) ?
?
? , ?
? ?
, ?
?
,
?
?
2.

,
; ,
, .
,
:
.
.
.
.
-, ,
. (,
. .) , , . .
,
,
. , ,
, ,
, .

32

3.
,
Drupal.
/
.

.
.
,
( 4),
,
, . .
, .
4.
Drupal .
, .
Drupal ;
( )
.
. ,
, , ,
, .
.
, Fireworks Photoshop.

HTML, CSS .
, .

, .
5. ,

.
13, :
1. .
2. URL- (,
URL-, staging.newsite.com) .
3. .
4. .
5. .
6.
URL-.
7. .
8. .
9. .
10. !
, , ,
Drupal.

I.
1 Drupal,

.
, Drupal,
.
8 30.
2
Drupal : Drush ,
; Git ,

.

1.
Drupal 7
,

,
Drupal.
(kombucha)

Drupal 7:
,
, ,
Drupal-.
.
.
Views, ,
, , JQuery;
, Commerce.
Drupal .
, ,
Drupal, .
Drupal. ( , 8,
.)
, ,
.
. , ,
! :
.
Drupal 7.
Drupal, ,
, .
(
) .

.
, !

:
, .
.
( 9.)

: ?
, , , .
.
,
9.

35

,
.
. ,
, .

, , ( ) ,
Drupal 7
,
, Drupal.
, DefinitiveDrupal.org ( DGD7)
:
t
Drupal.
, .
Drupal .
Drupal
.
, ,
,
, ,
. ,
.
, . ,
. (
, , ,
.)
, ,
.

.
? , , ,
, .

: ?

. .
.
, .
.

, .
, , ,
. ,
.
, ,
, .
. DGD7

36

1. Drupal 7

.
-: .

- ?
,
. .
,
.

, Drupal,
, Drupal .
, .
,
.
. , .
Drupal , ,
. ,
, .

:
.

.
,
.

.
,
, , Drupal, ,
.

.

.

( ),
.
,
. (
.)
,
(. 1.1). ,
, , ,
. , , ,
, .
. Drupal
, , , ,
.
.

37

. ,
.
-Vo

*7
AHACO+vUUiyUiAs

H&SoCMAs
I 4'

. 1 .1 .

Drupal, , , ,
, , .

, Drupal
. Drupal ( )
, , , ,
. . ,
( 6).
, ( )

. , ,
;
, .
DGD7 , ,
Apress. 15 16,
, .
, , ,
.
Drupal ,
. ,
.

38

1. Drupal 7

, ,
, (. 1.2).

IMAGE

UST
- List item
- List item
- List item
-lis tite m

1
2
3
4

This is the mission .statement te xt area. This is


the mission statem ent te xt area. This is the
mission statem ent te xt area The mission
statem ent te xt area is this area right here.
This is the mission statem ent te xt area. This is
-the mis'sion statem ent te x t^ re a . This is the
mission statem ent te xt area. This is the
mission statem ent te xt area.

UST
- List item
- List item
* List item
- List item

1
2
3
4

UST
| List item
* List item
- List item
- List item

1
2
3
4

. 1.2 . DGD7. HTML, (


, )

, ,
Drupal ,
.

, . .
, Drupal
. , , :
: ,
( ).
: , .
: ,
.
, , (
12).

,
.
.

39

Drupal
, Drupal.
(Linux, Windows, Mac OS X),
- (Apache, IIS, Nginx) (MariaDB/MySQL, PostgreSQL, SQLite).

Drupal Drupal.org
. http://drupal.org/project/drupal,
. 1.3, Drupal. ,
, Drupal 7.
Drupal core [ drupal.org - Moziila Firefox

BSe Edit yiew History gookmarits loois


0

v X- ! ij> http7/drupal .orq/orojeci/ftlrupe!

v] :> || f v

Download & Extend


Home

Drupal Core : M odife-

Them os ./ installation fto S tes

Maintainers for Drupa! core


Poshed by Drupat on S*pttmbet7$. 3003 & J
G et sta rted by dow nloading th e official Drupa! core fiies, T hese officias releases come bundled
with a variety oi m oduies and them es to give you a good starting point to he*p buHd y o u r s i
Onjpal core includes b asic community features Sifce blogging. forums, and contact forms, and
can be easily extended by downloading other contributed m odules and them es.

- 26645 Commits
i-jt: s 1 age, first- to years ago
WfSteehicfe - 7740 Commits
test-. 1 iaftk ago. fast. 2 years ago
drumm -1231 com m its

test:.2 week* ago. . * years90


G 4bw Moitsy - 3058 c om m its
lest; S weeks agdi first- 3 year *90
View a!! coowtftteni
n version number* can be found in th e online ito o n n

Issues for Drupa! core

Drupa! 7 is offictaiiy released!

To avohs dupiivate#. pfSftk* 'iwrcii ixrfore


bubnu&fag tw>* issue*.

Come coiefetate th e w o s s s i

_ j |ViSearch i

Advanced sow ch
D ow nload*

O at*

0.6 was j & |:w

ran-as

Caf,<}L'n,SS6! j j i p l i

2010-Dec-15

Notes

?.5t-dsv

2011-Jan-18

Notes

6.-dev

2010-Dec-15

Notes

tar.gz

V ersio n

AS; issues
9182 open,
B o g reports
, total

oidostopenissuw:SSVb92
Recent issues
?h#m ex Imprepwrfy check render
* wrti&ri determ ining visibility

, 1 .3 . Drupal-npoeiaa

- (. dgd7.
Drupal- index.php .htaccess
Drupal .

org/install).

( dgd7)
Drupal ( dgd7/web).
, , ,
(. 2).

Drupal sites/default/default.settings.
php sites/default/settings.php ( , ).

40

1. Drupal 7

Drupal settings.php.
-.
dgd7.org/install.
sites/default/files

, . ,
. ,
, Drupal.


Drupal (
). Ubuntu DGD7
http://dgd7.localhost; WAMP, LAMP
http://localhost/dgd7/web.
Drupal install.php.
. (
.) ;
,
drupal.org/localize (
Drupal, drupal.org/project/HOn_install).
(,
).
SQLite Drupal, ,
-. Drupal
SQLite. ( SQLite , ,
.) , Drupal
!

. 1 .4 . Drupal

41

( )
,
( ).


. .
.
, , 6, .

.

, Drupal! .
, Drupal 7 , , . 1.4.
,
.

Drupal
. 1.5 Drupal
.
Toolbar,
. :
.
, .
, .
, .
, .
.
.
.
?

Dashbo;3rd

Add content

Content

Struetune

Appearance

People

Modules

Configuration

Reports

Help

Bnd content

. 1 .5 . Drupal 7

.
Drupal Dashboard, ,
.
.
Shortcut ,
.
Configuration User interface Shortcuts (admin/config/userinterface/shortcut).
Shortcuts ( ID 7
user/7/shortcuts). ,
.
People Permissions (admin/people/permissions)

42

1. Drupal 7

Select any shortcut set. (


.) ,
Use the administration toolbar; ,
.

,
(admin/help/shortcut). , http://drupal.
org/documentat ion/modules /shortcut.


Drupal.
DGD7 , -
, Apress. , ,
Appearance (admin/appearance). ,
, , 15.

Drupal . drupal.org/project/
themes , 7.x. , Corolla (drupal.org/project/corolla),
Drupal 7, ,
.

Bartik, Drupal 7 , Color.


, (. 1.6).
Settings. Color set Slate,
(
Bartik, Drupal- ).

. 1 .6 . Bartik

, ,
, . 15 ,

43

. Bartik,
, .


Color .
. ,
, .



Drupal. , , Drupal.
, .

Drupal.org (. 4). , ( ,
, ).
. ,
Modules (admin/modules).


OpenID, , . 1.7,
Save .
3

OpenID

7.0

Allows users to log into your site using OpeniO.

. 1 .7 . OpenID admin/modules

( ,
) Core .
.
( Ctrl+F
Command+F).

OpenID
OpenID. OpenID
, .
Google, Yahoo!, Livejournal, Wordpress.com, MayFirst.org
AOL.com -; OpenID,
MyOpenID.com Yiid.com, .
openid.net. OpenID-
, drupal.org/project/openid_provider.

,
( Captcha, Mollom Antispam 4),
( ,
).
.

44

1. Drupal 7


Drupal , ,
, , .
,
.
Color Overlay.
Bartik,
. Overlay
. Modules (adm in/
modules) Save configuration .

Overlay?
(, node/add/page) More information
about text formats , .
, Firefox, . ,
, .
. Ctrl+Shift+T.
Overlay , .
( drupal.org/node/655388.
fixed for Drupal 7 ,
Drupal.) Overlay,
. ,
Appearance (admin/appearance).
Overlay
(, user/86/edit).


Drupal
. Drupal
. , .
, , ,
, .
, , ( )
. body ( ),
, .
, ,
file, image, listing option, .
.
Suggestion
,
.
Suggestion
. (
, , . .),
. ( ,
.)
Suggestion
Structure Content types. Add content type.

45

, ,
. . ,
, Add content type, ,
admin/structure/types/add.

Suggestion Description
. (node/add)
. ,
Submission form settings, ,
.
.
, .
Save and Add Fields.

Suggestion ; Comment
, .
, ,
. Comment settings,
/ .

Manage fields ,
. 1.8. , ,
, . (Drupal
.) : title
body. , , title
.
A

Dashboard

Add content

Content

Structure

Appearance

People

Modules

Configuration

Reports

Kelp

Heilo admin

Find content

Home * A dm inistrate

S u g g estio n

Log out
Edit shortcuts

Structure Content types, * Suggestion

manage fields

m a naged

The content type Su g g estio n has b een added.


Show row weights

LABEL

NAME

REID

Title

title

Node module element

4*

Body

body

Long text and summary

Add new field

Explanation

fields explanation

Labe!

Reid name (a~z* 0-9, J

Long text
Type of data to store.

WIOCET

OPERATIONS

Text area, with a summary

edit

delete

1 Text area {muitipte rows.) %


Form siemens m edrt the data.

Add existing field


f - Select m existing fieid Label

Field to share

Setect a widget - : %
Form eiennent to edit the data.

Save

. 1 .8 . Explanation. field
explanation ( field_ )

46

1. Drupal 7

,
, Explanation. Label
Add new field ,
Long text.
Label ;
Drupal. long text
; text
.

Drupal. ,
. ,
,
. , 15 16.

,
. (
, ,
Drupal 8; drupal.org/node/552604.)
, . 1.9,
. ,
Required field. ,
. Help text ,
Explanation. Rows 3, ,
. Text processing Plain text,
. ( Plain text Filtered
text .)
Number of values ( ,
!)
Save settings. .
Save

Save field settings, long text

SUGGESTION SETTINGS

These settings apply only to the Explanation field when used in the Suggestion type.
Label *
Explanation
Q

Required field

Help text
Optional background or rationale on why the above text should go in the Definitive Guide to Drupal.

instructions to present to the user below this field on the editing form.
Allowed HTML tags <a> <b> <> <code> <det> <em> <i> <fns> <pre> <q> <smaH> <span> <strong> <sub> <sup>
<tt> <ol> <ul> <0> <p> <br> <img>
Rows *

S Z I Z Z I Z Z
Text pro cessin g
Plain text

Filtered text (user selects text format)


. 1 .9 . long text

47


Drupal,
, .
URL-
. .
, .
,
. Basic page,
Drupal . Add content Basic page
(node/add/page).

DRUPAL 7
Add content ( Drupal 6 Create content)
, . ,
, Content.

Title Drupal 7, Body


-.
, Text format
Full HTML
Provide a menu link, . 1.10: Menu link
title , Description ,
.
, 5 Weight,
<Main menu>. !
M enu settin g s

Provide a m enu link

; Buy the Book

Menu link title

Book o utline

1..... .... .............................

Revision Inform ation

: Nerw revision

Buy the Book


Description
Purchasing the Definitive Guide to Drupal 7.

URL p ath settin g s


; Alias: purchase

; Shown when hovering over the menu link.

C om m ent s e ttin g s

\ Closed

Parent Item
| cMain menu>

A uthoring Inform ation

i By -' on

Weight

; 2010-07-0? 06:36:03 -0400


i
Publishing o p tio n s
| Published

i Menu links with smaller weights are displayed btfore finks with larger weights

1.10.

URL- (
, , node/1). URL
path settings URL alias purchase. . 1.10
.

48

1. Drupal 7

. 1.10 , Revision information New


revision. ,
. 4 ,
Content Type Overview.

,
.



, .
Add content, Title
Body. Publishing options
Promoted to front page Sticky at top of lists, . 1.11.
.
, (
).
Submission form settings
D e fa u lt o p tio n s
Publishing options

Published

Display setting's

Q Promoted to front page

Comment strttfngs

o Sticky at top of lists

Open. Tftttssrfing . 50 sor>iswji>ts jwjr page


Menu settings

Create new revision


Users with the Administer content permission wtli be able to override these options.

. 1 .1 1 .

Drupal ?,
Promoted to front page . ,
, .
Drupal, Content (admin/content).

:
, .
. . Drupal 7
; ,
Structure Blocks (admin/structure/block).
, .

( , ,
).

.
. Blocks Add block. Block description
Mission statement ( ). Block title
, Block body , . 1.12.

49

Block description *
Mission statement
A brief description of your block. Used on the Blocks administration page.

Block title
The title of the block as shown to the user.

Block body *
The Definitive Guide to Drupal 7 accelerates people along the Drupal learning curve by covering all aspects of building
web sites with Drupal: architecture and configuration; module development; front end development; running projects
sustainably; and contributing to Dnjpal's code, documentation, and community.

. 1 .1 2 . /
( ) admin/structure/block/add

DRUPAL 7
Drupal 4.0, 2002 ,
(General settings). Drupal 7
.

, Region settings, Highlighted;


Bartik .
Visibility Pages, Show block on
specific pages Only the listed pages.
<front>, . 1.13. Save block.
Visibility settings
Pages
i Restricted to certain pages

Show block on specific pages


All pages except those listed

Content types
Not restricted
Roles
; Not restricted

% Only the listed pages

<front>

Users
Not customizable
Specify pages by using their paths. Enter one path per Hne, The
character is a wildcard, Example paths are btog for the blog page
and /* for every personal blog, < fm n t> is the front page.

Save block

. 1 .1 3 . Mission Statement

,
.

Drupal ,
. , , , ,
, .

50

1. Drupal 7

DGD7 ,
, . 1.14.
Recent content Recent comments Sidebar first
( ,
. 1.15) .
Recent comments

The Definitive Guide to Drupal 7 accelerates people along the Drupal learning curve by
covering all aspects of building web sites with Drupal: architecture and configuration;

There's a drush command


for that! months l week
ago

module development; front end development; running projects sustainably; and contributing
to Drupals code, documentation, and community.

There are some who say


that 2 months i week ago
Putting the site online 4
months weeks ago
Additional background 7
months l week ago

The Definitive Guide?


"Definitive" is quite a claim to make. Not everyone who works in Drupal is good at all of it, or even can
know about all of it Which is fantastic news for us, the readers and users of this book.
No one expert in all areas, and so there are many onramps and avenues to becoming a Drupal expert. This
multi-author book gives many of these at the same time as providing an essential overview. Together, we
will learn how to think about and approach Drupal 7 and future releases.

Recent content
Disabling
Overlay Module
Benjamin

. 1 .1 4 . ,
Mission Statement

/l\

* The changes to these blocks wilt not be saved until the Save blocks button is clicked.
'
OPERATIONS

REGION

BLOCK
Header

No blocks in this region


Help

System help

*>

............z i

configure

Highlighted
i

Mission statement

configure

Hkjhtighted

delete

Featured

No blocks in this region


Content
4*

Main page content

Content

jji

configure

Sidebar first

4*

Recent comments*

Sidebar first

configure

Recent contem

Sidebar first

configure

i]

. 1 .1 5 . Recent comments Sidebar first,


, .
, ,
.
None Disabled.

51

:
Drupal
Taxonomy. ( )
. ,
, , , ,
(free tagging).
, .
;
,
.


. taxonomy/
term/8, 8 . ,
, .
, .
( 3 Views).
, , ,
, .

,
,
Drupal .
Suggestion; ,
.

Structure Taxonomy (admin/structure/taxonomy) Add
vocabulary . ,
Book element. edit
element, . 1.16.
Description, ,
, Content or concepts in, or suggested for, the book (
). .
Name *
Book element

Machine-readable name *
element
A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.

Description
Content or concepts in (or suggested for) the book.

Save

. 1 .1 6 . Book element Taxonomy

,
:

Add term.

52

1. Drupal 7

Tip ();
Note ();
Gotcha ();
Caution ();
Reality ();
New in Drupal 7 ();
Concept ();
Anecdote ().
Status
:
Dont waste pixels on it ( );
If theres room ( );
Slated to go in ( );
Already in the book ( ).
Suggestion .
, ,
,
Title Body.
Structure Content types.
Manage fields Suggestion. Add new field Label
Book element, Field name element,
Term reference.
. Check boxes/radio buttons,
. 1.17. Save.
**

Add new field

Book element)
Labef

fie!d_ dement
Reid name (a-z, 0-9, J

Termreference
' Type of data to store.

| Check boxes/radio buttons

Form element to edit the data.

. 1 .1 7 . Term reference

Number of values Check boxes/radio buttons ,


. 2 .

, ,
Book elements Save field settings.
Required field .

Drupal 7
. , ,
Location , , .

Status Suggestion,
, Required field.
, , Add content (
) Suggestion.
.
, . !

53


, Structure Contenttypes Manage Suggestion Fields
(admin/structure/types/manage/suggestion/fields),
.
(
Display fields). Save.
, DGD7,
. ? Drupal
.

,
Drupal .

. Drupal ,
.

Drupal 7
people (). , , -
user ().
(user settings).

Drupal :
(anonymous user) ,
.
(authenticated user) ,
.
(administrator)
.
; Drupal.
, . ,
Drupal,
. ,
Configuration People Account
settings (admin/config/people/accounts).

,
. , ,
. , ,
,
, editor
.

, . ,
, ,
. ,
. ,
.

DGD7
, .

54

1. Drupal 7


.
. , .
.
People Permissions Roles (admin/people/permissions/roles). ,
, author Add role,
. 1.18.
NAME

4.

OPERATIONS

anonymous user docked)

edit permissions

: *

authenticated user docked)

edit permissions

; '

administrator

autborj

edit role

edit permissions

Add roie

. 1 .1 8 . .

, Drupal ,
, .
, .
admin/config/people/accounts,
admin/people/create.
DGD7
, Status ,
. 8
Field Permissions, : ,
Status
.
Edit permissions
. ,
Permissions. ,
. ,
author, .
, .
, ,
, Taxonomy,
Status. :
Access the content overview page ( ).
Create new Basic page content ( ).
Edit own Basic page content ( ).
Edit any Basic page content ( ).
Create new Suggestion content ( ).
Edit own Suggestion content ( ).
Edit any Suggestion content ( ).
Use the administration pages and help ( ).
Use the administration toolbar ( ).
, author , .
People
.

55

Add user. . ,
Drupal ,
. (,
, , , ;
, , 12.)


. Update
options, . 1.19.

UPDATE OPTIONS
Unblock the selected users
M|
Update
! Unblock the selected users
I Block the selected users
J Cancel the selected user accounts

ROLES
(A d d a role to the selected users
1 administrator

author
1
I Remove a rote from the sele c te d users
I
administrator
je
administrator
i
author

. 1 .1 9 . author


, Drupal 7! ,

Drupal , .
Drupal, .
.
, :
Drupal 7 .
.
Mission
Statement .
, .
,
.
Drush Git,
Drupal . (
12, .) 3
Drupal Views.
4 ( ) Drupal 7.
. 8
DGD7.

dgd7.org/firstsite.

2. :
Drush Git

, .

,
Drupal, , Drush (
Drupal) Git ( )
. Drush Git
,
. Drush
, 25.
Drush? .
? drush up. ?
drush dl _.
Drush (. 2.1).
Dani-Nordins-HacBook-Pro:*' Deni$ cd 0ropbox/MAHP/drupal7
D ani-Nordins-MacBook-Pro:drupal7 Danii drush up
Refreshing update status information ...
Done.
Update information last refreshed: Fri, 01/21/2011 - 17:40
Update status information on all installed and enabled Drupal projects:
Name
Installed
Proposed
Status
version
version
Backup
7.X-2.0
7.X-2.0
Up to date
and
Migrate
7.0
Drupal
7.0
Up to date
core
7.x-1.0-alph
Chaos
7.x-1.0-alph Up to date
32
tool
a2
suite
7.x-1.0-beta Update available
Pathauto 7.x-1.0-alph
a2
1
Token
7.x-1.0-alph 7.x-1.0-beta Update available
a3
1
Views
7.X-3.0-alph
7.x-3.0-alph Up to date
al
al
Wysiwyg
7.X-2.0
7.X-2.0
Up to date
Boron
7.x-1.0-beta 7.x-1.0-beta Up to date
1
(HTML5
1
base
theme)
NineSixt
7.x-l.x-dev
7.x-l.x-dev
Update available
(960
Grid
System)

Code updates will be made to the following projects: Pathauto [pathauto-7.x-1.0-betal], To


ken [token-7.x-1.0-betal], NineSixty (960 Grid System) (ninesixty-7.x-l.x~devj

. 2 .1 . Drupal drush up 30 ,
15 ,

Git . ,
(Version Control System, VCS),
. ,
, : -

Drush

57

, ,
?
.
,
.
.
, ,
VCS. ,
,
Internet Explorer,
. .
, .
Drush Git.

Git , Drupal,
, .

Drush
Drush ,
Drupal , .
. Drupal
Drush -
. ,
,
.
.
- .
.
Mac OSX Ubuntu
. ,
Ubuntu Drupal.
.
Drush Git
. Mac OSX Coda
Panic ( www.panic.com/coda/),
Terminal. ,
.
,
Drush, , (
Drupal).
Drupal.
Drush (. )
.
cd/path/to/drupal ( /path/to/drupal
Drupal ).
Drush- drush _.

58

2. : Drush Git

Drush- Drupal ,
( sites/default); ,
c d / p a t h / t o /d r u p a l /s it e s /
example.com -1 h t t p : / /e x a m p le . com.
Drush Date. ,
cd Dropbox/MAMP/dgd7, Drupal (
):
Last login: Fri J a n 21 1 7 : 4 0 : 0 8 on t t y s 0 0 0
D a n i - N o r d i n s - H a c B o o k - P r o : *' D a n i $ cd D r o p b o x / M A M P / d g d 7
D a n i - N o r d i n s ~ M a c B o o k - P r o : d g d 7 D a n i $ d r u s h dl d a t e
P r o j e c t d a t e ( 7 , x - 1 . 0 - a l p h a 2 ) d o w n l o a d e d to

/Users/Dani/Dropbox/HAHP/dgd7/sites/all/inodules/date.
Project date contains 6 modules: date_views, date_tools, date_repeat, date_popup
, d a t e . a p i , date.
Dani-Nordins-HacBook-Pro:dgd7 Oani$ drush pm-enable date
T h e f o l l o w i n g e x t e n s i o n s w i l l be ena b l e d : d a t e _ a p i , d a t e
D o you r e a l l y w a n t to c o n t i n u e ? (y/n):
date was enabled successfully,
date.api was enabled successfully.
Dani-Nordins-Hac8ook-Pro:dgd7 Dani$ |

(Laura Scott)
; Drush.
Mac OS X, Unix- .

1. Drush
Drush drupal.org/project/drush. Drush
Drupal, ,
. 2.2. (Drush ,
!)
Drush was originally developed by Arto for Drupal 4.7 (this alpha code can still be found in the
DRUPAL-4 -7 branch). In May 2007, it was partly rewritten and redesigned for Drupal 5 by
frando. The module is now maintained by Moshe Wests man, Owen Barton, .Adrian Rossouw,
greg.l.anderson, and jonhatian.
P roject Information
Maintenance status: Actively maintained
Development status: Under active development
Module categories: Drush
Reported installs: 1284 sites currently report using this module. View usage statistics.
Last modified: January 6, 201.1
D ownloads
Recommended releases
Version

Downloads

All*-versions-4.1

tar.gr

Ail~versions3 3

tar,gf

Development releases
Version

Dow)

AlI-v rs ion s - 3. x -dev

tar.gi

Date

Open Link in New Tab


Open Link in New Window
Open Link in Incognito Window
Save Link As...
Copy Link Address

links

n-ll

Notes

|g ~ ll

Notes

*9-1

Notes

Links

Inspect Element
View ail releases

SOHO Notes Open

. 2 .2 . Drush-.
Recommended releases

Drush

59

tar ,
home. dev .

. drush
, README.txt. !
,
Terminal, tar.gz
home, . 2.3. **.
wget http://ftp.drupal.0 rg/files/pr0jects/drush-7 .x-4 .4 .tar.gz
;** Drush - wget **
tar xzf drush-7.x-4.4.tar.gz
;** **
rm drush-7.x-4.4.tar.gz
;** **
D a n i- N o r d in s - M a c B o o k - P r o : - D a n i$ w g e t h t t p : / / f t p . d r u p a l . o r g / f i l e s / p r o j e c t s / d r u s h
- A ll-v e r s io n s -4 . 1 .ta r .g z
2 0 1 1 -0 1 -2 1 1 8 :2 2 :5 2
h t t p : / / f t p . d r u p a l .o r g /f il e s / p r o 3 e c ts /d r u s h -A ll-v e r s io n s
- 4 . 1 . ta r .g z
R e s o lv in g f t p . d r u p a l . o r g . . . 6 4 . 5 0 . 2 3 3 . 1 0 0 , 6 4 . 5 0 . 2 3 6 . 5 2
C o n n e c tin g t o f t p . d r u p a l . o r g | 6 4 . 5 0 . 2 3 3 . 1 0 0 | : 8 0 . . .
HTTP r e q u e s t s e n t , a w a i t i n g r e s p o n s e . . . 2 0 0 OK
L e n g th : 2 4 3 7 1 1 (2 3 8 K ) [ a p p l i c a t i o n / x - g z i p ]
S a v in g t o : ' d r u s h - A l l - v e r s i o n s - 4 . 1 . t a r . g z *
1

2 0 1 1 -0 1 -2 1
43711]

%
1 8 :2 2 :5 2

2
(9 7 3

K B /s )

,
-

c o n n e c te d .

9 7 3 K /S

'd r u s h - A ll- v e r s io n s - 4 .1 .t a r .g z '

in
saved

0 .2 s
[2 4 3 7 1 1 /2

D a n i-N o r d in s -M a c B o o k -P r o :* * D a n ii t a r x z f d r u s h - A l l - v e r s i o n s - 4 . 1 . t a r . g z
D a n i - N o r d i n s - H a c B o o k - P r o : ~ D a n i $ rm d r u s h - A l l - v e r s i o n s - 4 . 1 . t a r . g z
O a n i- N o r d in s - H a c B o o k -P r o :^ D a n i$ |

. 2.3. Drush . Drush


2. Drush
. , , Drush
.
. home,
Finder.
Drush , .
chmod u+x /path/to/drush/drush ( /path/
to/ Drush). Drush dev, ,
:
chmod u+x dev/drush/drush

, Drush , ,
drush (, ,

).

.
, .
bash Drush,
.

60

2. : Drush Git

UNIX home :
- ( ).
bash home.
, :
cd ~

bash , home,
:
Is -

, , ,
. 2.4. (.); :
.profile
.bash_aliases
.bashrc
.bash_profile
Dani-Nordins-MacBook-Pro
Oani-Nordins-HacBook-P

Dani$ cd Dani$ Is -a
.drush
.freemind
.gem
.AB64CF89
.CFUserTextEncoding
.gitconfig
.DS_Store
.hAWabAzAr
.Trash
.htaccess
.adobe
.realobjects
.bash_history
. rnd
,bash_profile
.ssh
.crash_report_checksum
.subversion
.crash_report_frames
.viminfo
.wdswlock
.crash_report_preview
.cups
Applications
.dropbox
Desktop
Dani-Nordins-HacBook-Pro:*"' Dani$ |

Documents
Downloads
Dropbox
FontExplorer X
Library
Movies
Music
Pictures
Public
Sites
drush
drush-backups
qtm-blog

. 2 .4 . Is home

bash .
, , nano (
UNIX).
( . bash_prof ile).
nano .
:
nano .bash_profile

. .
, , , :
alias drush='/path/to/drush/drush'

/path/to/
.
home? , . 2.5.
alias drush= Wdev/drush/drush'

Jxport PATH=$PATH:/Users/Dani/drush

Get W n t e O a g Read Fffl Prev Cut Cur Pos


I Exit J u s t i f y Where Next PgQ UnCut g y To Spell

. 2 .5 . drush:
drush PATH .bash_profile .profile

Drush

61

, Ctrl+x,
Enter. .
bash source
. :

y(es)

source .bash_profile

4 .
.
. :
drush

Drush-. ! (,
, !) . 2.6.
D ani-Nordins-MacBook-Pro:^ Oani$ cd Dropbox/MAMP/dgd7
D ani-Nordins-HacBook-Pro:dgd7 Dani$ drush
Execute a drush command. Run 'drush help (command]' to view command-specific
help.
Run "drush topic' to read even more documentation.
Global options (see 'drush topic' for the full list):
-r <path>, root=<path>
Drupal root directory to use
(default: current directory)
-I http://exanple.com,
URI of the drupal site to use (only
urihttp://example.com
needed in multisite environments)
Display extra information about the
- V , verbose
command.
-d, debug
Display even more information,
including internal messages.
-y, yes
Assume yes* as answer to all
prompts
-n, no
Assume 'no* as answer to all prompts
- 5 r simulate
Simulate all relevant actions (don't
actually change the system)
-p. pipe
Emit a compact representation of the
command for scripting.
-h, help
This help system.
Show drush version.
version
The absolute path to your PHP
php
intepreter, if not 'php' in the
path.
(core)
Clear a specific cache, or all drupal caches.
Enter a new shell optimized for drush use.
Run all cron hooks in all active modules for specified
site.
Rsync the Drupal tree to/from another server using ssh.
core-rsync (rsync)
Provides a birds-eye view of the current Drupal
core-status (status,
installation, if any.
Read detailed documentation on a given topic.
core-topic (topic)
drupal-directory
Return path to a given module/theme directory.
(dd)
help
Print this help message. See 'drush help help' for more
options.
Flush all derived images for a given style.
image-flush
Evaluate arbitrary php code after bootstrapping Drupal
php-eval (eval, ev)

Core drush commands:


cache-clear (cc)
core-cli (cli)
re-cron (cron)

st)

. 2.6. !

,
Drupal. ,
Drupal, :
cd /path/to/drupal

, - .
drush dl . , Drush

, . , -
.
drush up. Drush
25.

62

2. : Drush Git

Git:
- .
, ,
,
.
, .
. 14 ,
( )
.

Git?
.
Git. , -, ,
, Drupal.org. ,
, Git.
. Git
Drupal-.

Projects using Git

Git is...
Git is a free A open source, distributed version control
system designed to handle everything from small to very
large projects with speed and efficiency.
Every Git is a futf-fiedged repository with complete
history and full revision tracking capabilities, not
dependent on network access or a central server.
Branching and merging are fast and easy to do.

Git is used for version control of files, much like tools


such as Mercurial. Bazaar. Subversion. CVS. Perforce, and

Cloning and Creating a Patch

The latest stable Git release is

*m
*

Download Git

UaaJSsmfii
release notes (2011 m -os)

KDE

Qi

MacOSX

Windows

PostgreSQL
Debian
X.orq

Other OQwnjoadOgtlgns

&&

Creating and Commiting

$ g it clone g i t ; //g ith u b .co m /g H /h ello -w o rI d .g it

$ cd (p ro je c t-d ire c to ry )

$ cd hello-world
$ (edit files)
t git add (files)

$ git inft
$ (add some files)
$ git add .

$ g it eosmit -m 4Explain what I changed'


$ g it fonsat-patch o rig in /m aster

$ g it commit -m I n i t i a l

emit*

. 2 .7 . Git.

Git:

63

,
(Distributed Version Control System,
DVCS). , Drupal.org Bazaar Mecurial (
Bazaar). Drupal-
Git.

Git
. ,
, gitscm.com.
, , . 2.7.

, UNIX- ,
. , Debian Ubuntu
sudo apt-get install git. Mac OS X Homebrew (mxcl.github.
com/homebrew) .
Windows Git code.google.com/p/msysgit
UNIX- Cygwin.

Git . Git ,
, Applications.
. ( Windows start
Git-.) g it.
drush, (. 2.8).
L a s t l o g i n : F r i J an 21 1 0 : 4 8 : 5 5 on c o n s o le
,O a n i-N o r d in s -H a c B o o k -P r o :* * D a n i$ g i t
usage: g i t I v e r s io n ) [ e x e c - p a t h [ < p a th > ]] ( h tm l-p a th ]
[ _ p i p a g i n a t e | n o -p a g e r ) I n o - r e p l a c e - o b j e c t s ]
[ b a re ] I g it - d ir * < p a t h > ) t w o rk -tre e = < p a th > ]
[ n a m e = v a lu e ] I h e lp ]
<command> [< a r g s > ]

Th e m ost commonly used g i t commands a r e :


add
Add f i l e c o n t e n t s t o th e in d e x
b is e c t
F in d by b i n a r y s e a r c h t h e c hange t h a t in t r o d u c e d a bug
b ra n c h
L i s t , c r e a t e , o r d e le t e b ranches
checkout
C h e c k o u t a b ra n c h o r p a th s t o t h e w o r k in g t r e e
c lo n e
C lo n e a r e p o s i t o r y i n t o a new d i r e c t o r y
com m it
R e c o rd ch an g e s t o t h e r e p o s i t o r y
d iff
Show c hange s b e tw e e n c o m m its , com m it and w o r k in g t r e e , e t c
fe tc h
D ow nload o b j e c t s and r e f s fro m a n o th e r r e p o s i t o r y
g re p
P r i n t l i n e s m a tc h in g a p a t t e r n
in it
C r e a t e an em pty g i t r e p o s i t o r y o r r e i n i t i a l i z e an e x i s t i n g
one
lo g
Show com m it lo g s
m erg e
J o in tw o o r m ore d e v e lo p m e n t h i s t o r i e s t o g e t h e r
my
H ove o r renam e a f i l e , a d i r e c t o r y , o r a s y m lin k
p u ll
F e tc h fro m and m erg e w i t h a n o th e r r e p o s i t o r y o r a l o c a l b ra n c h
push
U p d a te re m o te r e f s
a lo n g w i t h a s s o c ia t e d o b j e c t s
re b a s e
F o r v a r d - p o r t l o c a l com m its t o t h e u p d a te d u p s tre a m
head
re s e t
R e s e t c u r r e n t HEAD t o t h e s p e c i f i e d s t a t e
rm
Remove f i l e s fro m t h e w o r k in g
t r e e and fro m t h e in d e x
show
Show v a r i o u s ty p e s o f o b j e c t s
s ta tu s
Show t h e w o r k in g t r e e s t a t u s
ta g
C r e a t e , l i s t , d e l e t e o r v e r i f y a ta g o b j e c t
s ig n e d w i t h GPG

See g i t h e lp <command>' f o r m ore i n f o r m a t i o n


D a n i-N o r d in s -H a c B o o k -P r o :* ' D a n i$ |

on a s p e c i f i c

command.

. 2 .8 . git

64

2. : Drush Git

git git ,
( File Quit,
Cmd+Q) .

Git
Git .
,
.
Git- Drupal. ,
. , ,
. , SmartGit, drupal.
org/node/777182. Mac OS X Tower (git-tower.com).

Git-
dgd7.org/git.

:
, ,
:
git config --global user.name "Your Name"
git config --global user.email you@example.com


Git . . g it in it. (
cd).
.
, - DGD7,
1. :
cd ~/code/dgd7
git init

Drupal- .git, . 2.9.


.
S e e git h e l p < c o m m a n d > ' f o r m o r e i n f o r m a t i o n on a s p e c i f i c comm a n d .
D a n i - N o r d i n s - M a c B o o k - P r o : " ' D a n i $ cd - / D r o p b o x / M A M P
D a n i - N o r d i n s - M a c B o o k - P r o : M A M P D a n i $ cd d g d 7
D a n i - N o r d i n s - M a c B o o k - P r o : d g d 7 D a n i $ git init
I n i t i a l i z e d e m p t y G i t r e p o s i t o r y in / U s e r s / D a n i / D r o p b o x / M A M P / d g d 7 / . g i t /
Dani-Nordins-MacBook-Pro:dgd7 Oani$ |

. 2 .9 .

,
. ,

Git:

65

, CSS-
. , ,
. ( )
. ,
, .

. git add . .
Git,
( ) .
, ,
git status (. 2.10).
D a n i - N o r d i n s - H a c B o o k - P r o : d g d 7 D a n i $ git a d d .
D a n i - N o r d i n s - M a c B o o k - P r o : d g d 7 D a n i $ git s t a t u s
# On b r a n c h m a s t e r

#
# Initial
#

commit

# C h a n g e s to be c o m m i t t e d :
#
(use git rm c a c h e d < f i l e > . . . "
new
new
new
new
new
new
new
new
new
new
new
new
new
new
new
new
new
new
new

file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:
file:

to u n s t a g e )

.htaccess
CHANGEL0G.txt
COPYRIGHT.txt
INSTALL.mysql.txt
INSTALL.pgsql.txt
INSTALL.sqlite.txt
INSTALL.txt
LICENSE.txt
MAINTAINERS.txt
README.txt
UPGRA0E.txt
authorize.php
cron.php
includes/actions.inc
includes/ajax.inc
i n c l u d e s / a r c h i v e r , inc
includes/authorize.inc
includes/batch.inc
includes/batch.queue.inc

. 2 .1 0 . DGD7

, .
git commit, . 2.11. ;
Git .
, - .
, ,
(, - DGD7).
, :
git add .
git status
git commit -m " "

,
. ,
; Git .
(. 14).
,
(, )
.

66

2. : Drush Git

0ani-Nordins-MacBook-Pro:dgd7 Dani$ flit commit -m "Initial commit of files for 0607 demo site**
[master (root-commit) ddScSd4] Initial commit of files for 0G07 demo site
20S2 files changed. 461943 insertions(+), 0 deletions(-)
create mode 108644 .htaccess
create mode 100644 CHANGELOG.txt
create mode 190644 COPYRIGHT.txt
create mode 100644 INSTALL.mysql.txt
create mode 100644 INSTALL.pgsql.txt
create mode 100644 lNSTALL.sqlite.txt
create mode 100644 INSTALL.txt
create mode 100644 LIC0ISE.txt
create mode 100644 MAINTAINERS.txt
create mode 100644 README.txt
create mode 100644 UPGRADE.txt
create mode 100644 authorize.php
create mode 100644 cron.php
create mode 100644 includes/actions.inc
create mode 100644 includes/ajax.inc
create mode 100644 includes/archiver.inc
create node 100644 includes/authorize.inc
create mode 100644 includes/batch.inc
create mode 100644 includes/batch.queue.inc
create mode 100644 includes/bootstrap.inc
create mode 100644 includes/cache-install.inc
create mode 100644 includes/cache.inc
create mode 100644 includes/common.inc
create mode 100644 includes/database/database.inc
create mode 100644 includes/database/log.inc
create mode 100644 includes/database/mysql/database.inc
create mode 100644 includes/database/mysql/install.inc
create mode 100644 includes/database/mysql/query.inc
create mode 100644 includes/database/mysql/schema.inc
create mode 100644 includes/database/pgsql/database.inc
create mode 100644 includes/database/pgsql/install.inc
create mode 100644 includes/database/pgsql/query.inc
create mode 100644 includes/database/pgsql/schema.inc
create mode 100644 includes/database/pgsql/select.inc
create mode 100644 includes/database/prefetch.inc

. 2.11. DGD7

Git
Git .
, , , ,
:
git reset --hard HEAD

,
.

, ,
:
git checkout -- path/to/HNm<|>aMa.php
-php .
,
:

git revert HEAD

( )
:
git revert HEADA

Git-
, Git, ,
:

67

git status ,
.
git log .
, git log --pretty=oneline. ,
git log --pretty=oneline -n5 ,
, .
:q, .
git checkout mymodule.info
( ).
Git- man git.


Git
,
. , ,
. Drupal ( )
,
.
Drupal Git Backup, github.com/scor/dgb,

. 12.
,
Backup and Migrate (drupal.org/project/backup_migrate),
, .
Drush,

drush sql-dump > /path/to/.sql

. , Drush
; ,
. Drupal Git Backup, 25
, . ,
drush .

, , ( !)
.
,
,
. .

dgd7.
org/essential.

II.
3 Drupal-
Views. ,
.
4 (
), Drupal-,

.
5 Organic Groups,
.
Panels,
, Views.
6
,
.
7
Drupal.
8 ,
1, ,
,
,

. ,
Drupal, .

3.

Views

Views . , -
-, , ,
.
. ,
,
.
Views ,
.
.
. Views,
; , ! Views
.

Views?
, .
(view) , .
, .
Views Drupal ,
.
, ,
.
Views (Earl Miles), drupal.org
merlinofchaos. drupal.org/project/views
, .
,
, .
Views ,
.
drupal.org/pwject/views

Drupal, Views .

.
, ,
, .
, Views .
. ,
, .
,
Views, ,

Views?

71

, , .
, , , .

Views , .

Views
Views:
-;
;
, , ;
;
(. 3.1).
Published

Post date

Title

Type

Sun, 01/10/2010 12 38

Yes

Gemino Magna Pals

Basic page

Tue, 01/12/2010 -1 5:36

Yes

Expiito

Basic page

Sun. 01/17/2010 -18:07

Yes

Jus Mgs Mibh

Mgs

Si Sit

Basie page

Mon, 01/18/2010 - 1 3 40

Yes

Et Humo ibidem Lobortis

Basic page

Wed, 01/20/2010 - 06:15

Yes

Altquam Camur Inure Turn

Article

Sat, 01/23/2010 -11:50

Yes

Eum Ibidem Melior Vei

Basic page

Mon, 01/25/2010 -12:24

Yes

Exputo Feugiat PaJa

Article

. 3.1 .

, .
, Views .
, (page) (block).
URL- ,
.

9
Views
,
.

drupal.org/project/views.
Downloads, Recommend releases. ,
Drupal, 7.-3.,
(tar.gz zip).
.
sites/all/modules/contrib sites/all/modules.
Views sites/all/modules/contrib/views sites/
all/modules/views. (
Drush, 2).

72

3. Views

,
( user/1). , admin Modules.
Views. : Views,
Views exporter Views UI. Views ,
CTools. ,
enabled. CTools,
, disabled.
, , missing. Drupal
, ,
.
, , CTools drupal.org/
project/ctools. ctools .
/sites/all/modules, ,
CTools sites/all/modules/ctools.

CTools (Chaos Tools Suite) .

Modules (admin/modules) Refresh.


Views.
CTools disabled, . 3.2.
Views. Views Views UI
.
- VIEWS
ENABLED ; NAME

Views

I VERSION

DESCRIPTION

j OPERATIONS

Create customized lists and queries from your


database.
Requires: Chaos toots (disabled)
Required by: Views content panes (disabled), Views
exporter (disabled), Views UI (disabled)

V iew s

exp orter

V iew s UI

Allows exporting multiple views at once.


Requires: Views (disabled), Chaos tools (disabled)

Administrative interface to views. Without this


module, you cannot create or edit your views.
Requires: Views (disabled). Chaos tools (disabled)

. 3 .2 . . ,

Views exporter .

Views , Drupal
:
You must enable the Chaos tools module to install Views UI. Would you like to continue with
the above? ( Views UI Chaos tools.
, ?)
Please Continue. (, )

73


Drupal
(. 1 8).
. (anonymous user),
(authenticated user), ,
.

.

.

Administrative People Permissions.


Views. Views
: Administer views Access all views.

Permissions Views.
Views .

Administer views Views,


, .
,
. Administer
Administrator.
Bypass views access control.
, .
, Access all views.
, ,
, .
, Authenticated User Anonymous User ,
Administrator . - ,
Save permissions.

.
,
: , Firefox,
Chrome, Internet
Explorer.
.

! Views
. .


Administration Structure
Views (admin/structure/views). ,
.

74

3. Views

Advanced Help
Advanced
, . 3.3.

Help,

If you install the advanced help module from http://drupal.org/project/advanced.heiprView s


will provide more and better help. Hide this message.

. 3 .3 . , Advanced Help

Advanced Help
,
. drupal.org/project/advanced_help
Hide this message.



Add new view Import .
.


.
,

.
View Name, Tag Path.
, .
Settings .
Show filters on the list of views Save.
Search,
, , . 3.1.
3 .1 .

Tags

( ),

Displays

, : URL-,
,

Types

, : , ,

Storage

: , ,
( )

Status

,
Reset , (. 3.4).
Reset

Search
Filter

; All tags

; All displays

All types

All storage

All status j$;

. 3 .4 .

75


Views ,
.
. .

(. 3.5).
1

enable

. 3 .5 .

.
1. ?
, .

(machine name).
2. ?
, ,
.
.
3. ?
.
, .
, , ,
, internal.
4. , , ?
.
, URL-
. D rupal , .
, http://www.example.com/archive,
archive.
5. ?
.
/
Views.
, .
, .
clone export, .

, .
Enable, , , ,
.

76

3. Views

6. ?
.
, - ?
. , -

.
7. ? .
In code .
.
Database overriding code
, .

In database ,
.

8. ?
,
, , , . .
,
(admin/structure/views)
. . 3.2 ,
Views. .
, ,
, .
.
3 .2 . Views

Archive

Backlinks

, ,

Front page

Drupal.
,

Glossary

Recent comments

Taxonomy term

Tracker


Views .
. ,
, .
.
Front page. Operations Enable.
,
Edit.

77

,
.
Edit. .
, , ,
, .
Disable. ,
. ,
.
Clone. ,
.
.
.
.
Export. .
, .
.

, ,
.

Edit
Front page

Emulates the default Drupal front

Displays. Feed, Page

page; you may set the default home

In code

page path to this view to make it

Type: Content

your front page.

default

Front

page, . 3.6.
edit

frontpage, rss.xml

'

disable
clone
export

. 3 .6 .


Edit .
Front page.
.
, . 3.7.
D isplays
1 ^*Add
:

edst nam e and description

analyze

Page details

d on e
export

Display nam e: Page

. 3 .7 . (),

Front page : ()
Feed (). +Add,
. , .

. clone export ,
. :

78

3. Views

Edit name and description. . 3.8 ,


,
.

. . Views
,
.
, , ,
.
View name and description

Human-readable name

__ ____

Front page
A descriptive h um an -readab le nam e for this view Sp aces are allowed

View tag _ ______

.default

O;

Enter an optional tag for this view, it is used only to help sort views on the administrative p a ge

View description

______ __

;Emulates the default Drupal front page; you may set the default hon;
This description will a p p e a r on the Views administrative Ul to tell you w hat the view is about

Apply ^

Cancel

. 3 .8 . ,


.
Analyze.


. . 3.9
, , ,
.
, .
, ,
.
, ,
.

Page details
Display name: Page

clone page

TITtE

PAGE SETTINGS

Title None

Path: frontpage

FORMAT

Menu: No menu
Access: None

Format. Unformatted lisi ; Settings


Show: Content ; Teaser

FU.TER CRITERIA

add

Content Promoted to front p age (Yes)

HEADER

dd

FOOTER

add

PACER

Content: Published (Yes)

>SORT CRTTERIA

A d v an ced

Use pager: Full


add

>

Paged, 1 0 items

<>

Content: Siicky (desc)


Content: Post date (desc)

. 3 .9 .

79


,
.
Display Name
, , .
.
:
Name ().
. ,
. ,
: , , ,
.
block.
, , Block: 5 recent (: 5 ) Block: 5 random
(: 5 ).
Description (). ,
.
Title
.
, 1, .
. Title
. 3.10 :
For .
,
This page (override). All displays (except overridden)
.
Title .
Page: The title of this view
For All displays (except overridden)^

This title wtll be displayed with the view, wherever titles are normally displayed, i.e. as the page title, block title, etc.

Apply

Cancel

. 3 .1 0 .

Format
HTML- ?
(list), (table), (grid)
(unform atted), d iv .
.
Settings. CSS-
.
Show.
.

80

3. Views


|,
.
Fields,
.
Fields
Show Content (),
.
.
, Drupal.
Filter Criteria

. Content Published (Yes).
, :
, .
, .
Sort Criteria
? Content
Post date (desc). (
), .
Display Settings
.
.
Path. URL-, .
http://www.example.com/frontpage.
Menu. , .
.
Access. ,
. None - .
Header
, ( )
?
Footer
, ( )
?
Pager
.
Use pager. 10 ,
35, Drupal .
,
10 .
.

81

More link ( ).
. , ,
,
, .

Contextual Filters
,
URL-. Arguments.
Relationships
, ,
, (relationships).
: , , .
, ,
, .
. , .
No Results Behavior
- ,
? . , Empty text.
Exposed Forms

Exposed form in block. , :


?
.
Exposed form style. ,
.

Other

Machine Name. .
.
Comment. , .
Display Status. ,
.
Use AJAX. , ,
, ?
Hide attachments in summary.
.
Use grouping. , , ,
? ,
, .
Query settings.

Disable SQL rewriting. ,


?
node_access hook_query_alter().
.
Distinct. ?
.

82

3. Views

, ,
, ,
.
, .
, ,
.
.
Use Slave Server. .
, .

Caching. ,
? ,
. ,
.
,
, .

.
Link display. ,
More? , ,
, ,
, ?
CSS class. CSS- wrapper d iv ,
?
Theme. , , ,
. ,
. ,
,
.


.
,
.
,
, . ,
, ,
.
.
.

.
, . 3.11.
TITLE
Title: New Title
. 3.11. ,

83

:

. , ,
Filters section .
. Front page .
Content: Promoted to front page, ,
. 3.12.
Configure filter criterion: Content: Promoted to front page
For All displays

Iff ;

Whether or not the content is promoted to the front page.


Expose this filter to visitors, to allow them to change it.

Promoted to front page


Yes

No
-MORE
A dm inistrative title
This title will be displayed on the views edit page instead of the default one. This might be useful if you have the same
item twice.

Cancel
____ Remove
*_____
V, Apply* ^ 4______

. 3 .1 2 .

.
,
, , .
Content: Promoted to front page. . Content ()
, a Promoted to front page ( )
.
For All Displays ,
, .
, .
. ,
.
: Yes No. ,
. , , ?
? Yes.
:
Apply. .
.
Cancel. . ,
.
Remove. , ,
.

Configure filter criterion.

84

3. Views

:
.
, ,
.
.
, ,
.
Filters section
Content: Published.
. : ,
? ?

, , ,
. -
, , .
,
.
.

Cancel, .


Views
. , , :
;
.

.
,
, .
, . , - ,
,
.
Filter Criteria ,
And/Or.
Page: Rearrange filter criteria, . 3.13.
For, ,

.
, Operator And.
.
( Front page) Or
, .
,
.
Create new filter group
Operator; ,
,
. ,
.

85

Page: Rearrange filter criteria


For Alt displays

jjp j]

+ Create new filter group


Show row weights

i........~.~
t t ....... .. ......T"..7.... ... .......1
nr...._
O perator And j'
Content: Promoted to front page Yes AND
Remove

Apply

Content: Published Yes

Remove

Cancel

. 3 .1 3 . And/Or

; :
(( ) ( D)).
Content: Published Yes , .

, More .
, Administrative title.
.
, .

:
, , Sort criteria
.
. Front page .
Content: Sticky.
: Sort ascending Sort descending. , ,
?
, Sort descending.
, ,
.
Sort criteria Content: Post date.
. : ,
, ?
, , ,
Sort descending.
,
.
.
.
.
,
.
Cancel .

86

3. Views


, , .
? ?
Format, . Front page
d iv .
Settings, . 3.14, , CSS- .
FORMAT
Format: Unformatted list

Settings

Show: Content j T easer

. 3 .1 4 .


Show. ,
.
Content .
Teaser .

Content Show . Views
Fields Content.
, .
,
HTML-.
Teaser.
View Mode Teaser.
Read More.
, ,
.

, . 3.3.
3 .3 .

Grid

HTML List

Jump Menu

Table

Unformatted

div CSS-


. ,
. Views (adm in/
structure/views) Add new view .

87

,
, , .
, .



. , .
.

.
.

, :
1. . , - ?
2. . ,
?
?
3. . ?
4. . ?
5. /. ?
6. . ?
7. . ?
8. /. URL-
?
? .



Add new view. !
Structure, Views (admin/structure/views)
Add new view.
, ,
, .
.
articles by . , articles
by Bob ( ). .
Description, ,
. , .

.
show Content of type Article tagged with ___ sorted by Newest first. To
,
.
, Create
, .

88

3. Views

Page title Path


. Bob,
Articles by Bob, : articles-by-bob.
, Display format:
(
.) .
Items to display, ,
10.
, RSS-,
.
Create a block ,
.
. 3.15, ,
. Continue & edit .
Home * A dministration Structure Views

View name
iarticles by bob

\
Machine name; articles, by.bob Bait}

Description
Show articles authored by a specicif person

Show Content

of type Article

; tagged with

O ' sorted by Newest first

Create a page
Page title
articles by bob
Path
http://localhost/dgd 7 ,20110424/ aiticles-by-bob
Display format
Unformatted list Q : of I teasers

; with links (allow users to add comments, etc.)

without comments ;

Items per page

<10.... ~

13 Create a menu link


0 Include an RSS feed

Create a block
Block title
Articles by Bob
Display format
Unformatted list

o f ; titles (linked) ;

Items per page

Save & exit


-----

Continue & edit

Cancel

4 - . ......

. 3 .1 5 .

/ .
, ,
. , ,
.

89

URL- admin/structure/views/edit/articles_by_bob.

articles_by_bob ,
.


,
. ,
.
,
.
, , Display name.
Page: by . ,
. Description.
Apply Save, .
.
,
.


(
) , ,
.
Title : Articles by _.
, ,
. . ,
Apply.


. ,
, Content:
Published. .
, .
, .
Add Filters Criteria. Filter User
User: Name. Add and Configure filter criteria.
Operator Is one of.
, Bob.
.

.
.
Add . .

, !
, . 3.16.

90

3. Views

FILTER CRITERIA

add

Content. Published (Yes)


User: Name ( Bob)

. 3 .1 6 . ,


Format. , ,
. Show
Content | Teaser, .
,
.


, Content | Teaser.
HTML-. Content | Teaser
Content | Full Content .
div, .
, d iv CSS-.
/. Settings
Format, , CSS-.
, CSS-
. CSS Class,
Other Advanced.


, ,
.
Sort Criteria Content: Post date (desc),
, .


Use Pager: Full . ,
. ,
. Cancel,
.
Paged, 10 items,
. , 10 , Items per
page 15.
Exposed Options. ,
.
,
.
,
Apply.

91


.
Page settings No Menu.
Normal menu entry. Articles by _ Title. Menu Main Menu.
Apply.

Menu Tabs, , .


Use AJAX ,
. yes,
, HTML , , .
, ,
Use aggregation Query settings.
.
(time-based cache) ,
. ,
, , ,
.
Caching .

,
.
Tools Clear Views Cache.


Views ,
. Auto Preview.
;
, .


Views
. ,
,
, .
, , Articles by Bob,
, , ,
. ,
.
Title.
Edit Title, . 3.17.

92

3. Views

Titlej0^|
A rtk

Edit Title

. 3 .1 7 . ,

, Title
.
Apply.
, ?
,
Page: By _ details, ,
. , !


.
, . ,
http://example.com/articles-by-_. ,
,
, .
! ....


, ,
.
.
,
.

, ;

Add . ,
.
, Block
.

,
, Block: titles only (: ).

. ,
, , (
).
Show Row Style.
Show Format .
, Fields.

93

Fields, ,
( For
This block (override)). Cancel, .

,
, .
Fields, ,
Content: Title.
1. Content: Title, .
2. (
, ).
3. , Link this field to the original piece of content,
.
, HTML- .
d iv ,
, .
4. Style Settings.
5. Wrap field in HTML
. HTML element 2.
6. Create a CSS class title.
. 3.18.
Configure field: Content: Title
For Ail displays

The content title

ID link this field to the original piece of content

Enable to override this fields links.


Create a label

Enable to create a label for this field

Exclude from display

Enable to load this field as hidden Often used to group fields, or to use as token in another field.
-STYLE SETTINGS

Wrap field in HTML


HTML e le m e n t

[ H2 ... .... ..

Choose the HTML element to wrap around this field, e g. HL H2., etc.

Create a CSS class


CSS c l a s s
title

Provide a CSS class to...

Apply
4

Cancel

'

...

Remove

. 3 .1 8 . title

7. Apply, .

94

3. Views

More
More (),

.
More Link: No Pager Settings.
, For,
. This
block (override).

Create More Link, Apply


, . .
More. ,
, ,
.

: ,
Page?. ,
. , : ?
Link display:
_. ,
, summary, RSS feed, More . .



. .
8.


,
. , ,
.


. ,
, ,
.
,
, .
Add
No Results Behavior. Global: Text area Add
and Configure.

Label default. ,
, There are no articles available yet. Check back soon as we are updating
content frequently ( , .
, ). Apply.
-
, , ,
.

95

, For,
,
.



15 .
. ,
.
,
, 14 .
:
1. .
2. Page: Highlight.
3. Path Page Settings highlights.
, .
4. Format Show Full content. ,
For This page (override).
5. Use pager Display a specified number of items
Items per page 1.

Display Page uses


a path but the path is undefined. He .
, ,
.

1.
2.
3.
4.

5.
6.

7.

,
, .
.
Attachment ().
Attach: table to highlight.
Show Fields.
.
Add Fields. Content: Post Date
Add. Date Format
Apply.
.
Format Unformatted Table.
Table style option .

. , .
.
.
Pager, 14
(offset) 1. ,
14. , ,
.

96

3. Views

8. More, Pager Create more link.


9.
, Attach to: Not defined Attachment Settings.
Page: Highlight Apply. Before
Attachment position After.
.
10. Highlights.
.


.
, .
, ,
, (. 3.4).
3 .4 .

:

Name = Page: landing

Title = Content

Content: Published =Yes

Content: Title

Content: Type = Article


Element Class = H2
Label

Content: Post Date = Sort Descending

Use Pager = Display all items

Style = HTML List


List Type = Unordered List

Path = content
Menu =Normal Menu Item
Title = Content
Menu = Main Menu

Name = Page: Articles

Title = Articles

Path = content/articles
Menu = Default Menu Tab
Title = Articles
Parent Menu Item = Already Exists

Name = Page: Blog

Title = Blog

Content: Type = blog

Path = content/blog
Menu = Menu Tab
Title = Blog

97

Page:

Name = Page: Events

Title = Events

Content: Type = event

Path = content/events
Menu = Menu Tab
Title = Events

, .
Content, . 3.19.
Content

Content
j Articles j Blog

Events

Haero Neque Patria Turpis


Nunc Qui Quidem Ulciscor
Duis Erat Molior Vulputate
Letalis Rusticus
Abico Antehabeo Camur Fere
AutemVirtus
Antehabeo Nostrud Qui Tego
MeliorMeusTego
Abdo Ratis

. 3 .1 9 .




.
Views . ,
.
,
, . 3.20.
. 3.5.

All Content
Use the filters below to refine what displays in the list.
Published

<Any>

N ode: T yp e

Is one of

N ode: P ost date

Article
*
Basic page

Postdate

Is between

H!

Apply..,

Published

Title

Type

Gemino Magna Pala

Basic page
Basic page

Tue, 01/12/2010 - 15:36

Yes

Exputo Mos SI Sil

Sun, 01/17/2010-18:07

Yes

Jus Mos Nibh

Basic page

Mon, 01/18/2010 -13:40

Yes

Et Humo Ibidem Lobortis

Baste page

. 3 .2 0 .

98

3. Views

3 .5 .
:
:

Title = All Content

Content: Published
EXPOSE
Published = <Any>
Options =Yes
Content: Type
EXPOSE
Unlock Operator= Yes
Optional =Yes
Force Single = No
Content: Post Date
EXPOSE
Operator = Is Between
Unlock Operator = Yes
Optional =Yes

Content: Post Date


Content: Published
Content: Title

Content:

Use Pager = Display all items


Access = Role
Administrator

Format = Table
,
Post Date
Default Sort, Descending

Global: Text Area


Path = administer/content
Menu = Normal Menu Item
Title = Content
Menu = Navigation

, ,
. , ,
, . ,
.
.
.

99


, URL-
. , ,
,
. ,
, URL-.
, ,
, ,
, & . . 3.6.
3 .6 .
View

Title = Blogs

Show = Content | Teaser

Content: Published =Yes

Content: Post Date = Sort Descending

Content: Type = Blog


Page Settings Path = blog
Menu = Normal Menu Entry
Title = Blog
Menu = Main Menu

User: Name
NOT URL = Show
Display all results for the specified field
Override Title = Blogs by %1
Specify validation settings = Basic Validation,
Display contents of No results found
More:
Case = Capitalize each word
Case in path = lowercase
Transform spaces to dashes in the URL = Yes

Block

User: Name
Action to take if argument is not present = Display
a summary
Sort order = Ascending

Pathauto (drupal.org/project/pathauto)
URL-, .
. ,
, Pathauto
blog/[user]/[title].

/*,
, .
Blog .

100

3. Views

Relationship ,
, .
.
,
/ .
, . ,

(wiki node). . 3.7.
,
username.
.
, , . 3.21.
3 .7 .

Show = Fields

Content: Title

Wrap field and label in HTML = H2
User: Name
Label = Created by
More: Administrative title = Created by
User: Name
Label = Revised by
More: Administrative title = Revised by
Content: Body
Label
Formatter = Trimmed, 300

Content Revision: User

User: Name (2-


Revised by)
Relationship = revisions user

Style = Grid
Number of columns = 3

User pager = Paged output, full pager


Items per page = 9

laceo Metuo Sed Si


Created by. joe
Revised by; mlche
Brevitas melior metis nulla nunc
pagus pala vel. Brevitas dolor exerci
mauris odio si. Abdo quibus ratis
voco. Aptent dignissim olim...

. 3 .2 1 . , ,

101

, ,
.
.


. , ,
, , .


, Views, ,
. ,
, .
, .
:
Views Bulk Operations (VBO) drupal.org/project/views_bulk_operations.
:
OpenLayers drupal.org/project/openlayers;

G m ap drupal.org/project/gmap;

:
Calendar drupal.org/project/calendar.
:
j Carousel drupal.org/project/jcarousel;
V iew s Accordion drupal.org/project/views_accordion;
Views Infinite Scroll drupal.org/project/views_infinite_scroll.
,
, ,
.


! ...
,
. , .

Display Status Basic Settings.
?
, .
? ?
, ! .
, ,
;
. , -
.
, ,
. 21
.info .module. views
. .

102

3. Views

, .
articles_by_author.inc.

.inc

<?php
//
$views[$view->name] = $view;

/admin/structure/views
, . Export
Operations. .
articles_by_author.inc .
, ,
views .
, Views
views. .module.
dgd7glue :
/**
* hook_views_api().

*/
function dgd7glue_views_apiO {
return array(
'api' => '3.0'j

);
}
/**
* hook_views_default_views().

*/
function dgd7glue_views_default_views() {
$path =
. drupal_get_path('module', 'dgd7glue') . /views/*.inc';
$views = array();
foreach (glob($path) as $views_filename) {
require_once($views_filename);

return $views;

}
admin/modules.
, Views
, . Views Tools
admin/structure/views/settings/advanced Clear Views Cache.
.
. Database overriding code. , Drupal
, .
, , .
Revert Operations .
. Yes, I want to Revert my View!,
.
In code.
!

. .

103


, Views,
Drupal . ,
:
Drupal. ;
Views ,
.
drupal.org/documentation/modules/views

Views.
. , .
, .
drupal.org/project/issues/views

Google. , ,
Views.
google.com/search?q=drupal+views

Drupal-. ,
.
!
groups.drupal.org/groups

.
. 9
, (
, !).

4.
,

,
Drupal: .
, Drupal.
,
. , :
1. , .
2. , .
,
Drupal.
.
.

.

, ,
. Drupal, , ,
, .
Field Views. ,
? .

Drupal-
Drupal. NodeOne
49 , (nodeone.se/blogg/49modules-you-should-know), .
, , , ,
. Palantir Better
Know a Module (palantir.net/blog/series/14), .
, Drupal- 10 100 ,
.

,
Drupal- ,
: ,
.

(Khalid Baheyeldin) 2bits.com ,
Drupal -
,
-, , , SQL-
Drupal, .
, , Drupal,
. :

105

/ ;
;
.
,
,
. ,
. .
Drupal ,
. , ,
;
. 11
- .


, .
Drupal
;
.
, Views,
, .
,

.
, ,
, ,
:
. Drupal.org
Drupal.
drupal.org/project/modules,
. 4.1. .
.

Most installed, ,
Drupal.
, Drupal 7,
Drupal 6.
drupal.org/project/usage/_oy View usage statistics.

. Drupal.org
.
. ,
Actively Maintained
. , ,
,
, .
. 4.2 Views.
drupal.org/project/views ,
.

106

4.

Download & Extend


Download & Extend Home

Drupal Core

: Modules : Them es

Translations

installation Profiles

979 Modules match your search

Most Installed
Views

Modules categories: >

Content Construction Kit (CCK)


Token

Filter by compatibility:

Pathauto

Search Modules:

More Most installed

Sort by: ; Most installed j$j|

New Modules
Pages

Contributed modules are ad d -o n s for Drupal, allowing you to extend, build, and customize
Drupais core functionality* These modules are not part of the core files and may not have
optimized code/functionality for your purposes. If there isnt a module to solve your needs, you
can create one for the rest of the community to use, or consider joining forces and helping the
mamtainer. You can also view a full index of m odules listing only their titles. See the handbook
page for help on installing modules,

Real name registration


PantaRes Siren Core
File viewer

More New Modules

page for help on installing modules.

. 4 .1 . drupal.org/project/modules
,

Project Information
Maintenance status: Actively maintained
Development status: Under active development
Module categories: Content Display , Views
Reported installs: 2 6 4 9 7 4 sites currently report using this module. View usage statistics.
Last modified: January 5, 2011

Downloads
Recommended reteases
Version

Downloads

Date

7.x~ 3 .0 -alpha!

tar.gz 9 mb) j zip a69 MS)

2011-Jan-0 6

Links
Motes

6. -22

tar.gz u.ss ms? { zip ( u s ms?

2 0 1 0 -D e c -15

Notes

Version

Downloads

Date

Links

S.x-3.0- a!pha3

tar.gz {1.56 MS) | zip 0.74 MB)

2010-A pr-07

Notes

Links

Other reteases

Development releases
Version

Downloads

Date

7.x*3.x~dev

tar.gz o49 MS) J zip n m m

2Q11-Jan~12

Notes

6*x~3.x~dev

tar.gz <i.S6 ms) } zip ti.76 MS)

2011-jan-12

Notes

View ail releases

. 4 .2 . Views

Last release, ,
.

107

Full projects.
, .
,
,
(sandbox projects).
. ,
. ,
Drupal.org, .
.
, , ,
.
. !
,
Drupal IRC ( 9),
Contributed Modules Idea, groups.drupal.org/
contributed-module-ideas. , -
,
.

-

Drupal, ,
, ,
. .
Drupal- .
, , (issue queues) Drupal.
org. ,
. ,
, ,
.
. , ,
drupal.org/patch.


Drupal , ,
:
Block . ,
,
. URL-,
, ,
.
Color .

.
, Color .
Comment
.
, , .

108

4.

, ,
. Drupal 7
.
.
Dashboard .
,
(
).
Database Logging .
,
.
.
Field SQL Storage, Field Ul
, .

Text:

Contextual Links

File;

Options;

List;

Number;

Image.

Help .

, Drupal.
Menu .
Overlay . ,
( /
) .
.
Path URL- .
Drupal node/[node ID],
node/123.
. Pathauto,
, .
RDF . ,
, , , ,
.
.
Search .
,
.
Shortcut
. ,
.
Taxonomy
. ,
, .

109

(single select), (multi-select)


(free tagging).
Toolbar
Drupal.
Update manager Drupal .
,
.
, Drupal :

Filter .

Node

System .

Text .

User
.
, .
, :
Aggregator RSS-.
.
Blog
, . .
Views.
Book .
Contact ,
, .
Content translation .
Forum .
Locale
. , Content
, .
. Drupal 7
,
dgd7.org/translate.
Open ID Drupal
.
filter
Drupal.
,
.
Poll .
, .
Profile Drupal 7 ,
, .
, Fields Profile2.
Syslog Database
logging ( Debian Ubuntu /var/log/syslog).
Testing
Drupal .

110

4.

.
,
.
Modules Drupal (
Modules admin/modules),
. ,
Drupal.

Tracker

Trigger


Drupal, ,
. sites/all/modules/contrib.

( ). contrib
( ) ,
sites/all/modules/custom ( ).
. ,
Drupal, sites. ,
(. 7),
, .


Drupal.org,
drupal.org/project/modules. ,
Drupal; ,
, .
, , .
,
.
, ,
.
, ,
drupal./]1/__.

Drush drush dl
__ sites/all/m odules/
contrib , .
sites/all/modules. Drush 2,
25.

Views
views.
Views
.
, ,
.
, , .

111

Views ,
, , .
,
, -
Views.
.
Views UI, .
Drupal ,
, Views UI.

Chaos Tools
ctools.
Chaos Tools, CTools,
, .
Drupal , ,
AJAX-. CTools
Views.

3, CTools
CTools
.

Views UI.

(11.^/]1:/__. ,
CTools drupal.org/project/ctools.
Drush : drush dl ctools.

Pathauto
pathauto.
Drupal
. . ,
node/1. Pathauto
URL- .

, Token.
,
, , ,
example.com/blog/blog-post-title. Pathauto
Token (. ). Pathauto 8.

Token
token.
Token
, .
. ,
URL- Pathauto,
[node:content-type:name]/[node:title] Education
is the path from cocky ignorance to miserable uncertainty, URL-
example.com/article/education-path-cocky-ignorance-miserable-uncertainty.

112

4.

, Pathauto,
, , .
Configuration Search and Metadata
URL Aliases, Settings (admin/config/search/path/settings)
Strings to Remove.


Drupal 7 Content Construction Kit ()
, ,
, , . Drupal 7
Fields Fields UI.
,
Fields:
References (drupal.org/project/references) .
Relation
(drupal.org/project/relation),
. Block reference (drupal.org/project/blockreference) View reference (drupal.org/
project/viewreference), , ,
.
Field Group (drupal.org/project/field_group) ,
.
,
. ,
.
Link (drupal.org/project/link)
URL-.
Media (drupal.org/project/media) ,
, ,
.
Drupal.
Drupal.org . ,
, ,
.

WYSIWYG
wysiwyg.
Drupal
HTML-, . ,
HTML, ,
- .
VWSIWYG, , , , TinyMCE, CKEditor FCKeditor.

WYSIWYG- .
WYSIWYG (What You See Is What You Get , ),
. HTML-
, , .

, , BUEditor (drupal.org/project/bueditor).

113

WYSIWYG
sites/all/libraries folder.
README.txt .
WYSIWYG line breaks (drupal.org/
project/wysiwygjinebreaks). HTML-,
WYSIWYG-.

WYSIWYG. ,
, , .
BUEditor (bueditor),
HTML-. Markdown (markdown),
Markdown.
,
. ,
( : * *),
( : __) . .

W ebform
webform.
Contact

( user/[uid]/contact). , .
, .
,
.
. ,
,
. Webform,
.
, , .
, .

AntiSpam Mollom
antispam mollom.

. Drupal
.
AntiSpam Mollom.
, ,
.
Mollom Drupal (Dries Buytaert).
,
. Mollom.
com .
Mollom (adm in/config/content/
mollom/settings).

114

4.

, , Mollom .
, When
Mollom is down or unreachable Accept all form submissions.
AntiSpam akismet.com.
. Akismet
.
Word Press. Mollom.
(admin/config/content/antispam/settings).

, ,
. Antispam.


(drupal.org/project/captcha), ,
.
(drupal.org/project/recaptcha),
() . ,
Hashcash (drupal.org/project/hashcash),
. JavaScript-
, , ,
.


,
Drupal, ,
. ,
, Drupal.org.


Drupal-
.
Workbench
workbench.
, ,
.
Environment Indicator
environmentjndicator.
, , (
, , . .). ,
. , ,
.
Smart Crop
smartcrop.
. ,
,

115

. ,

.
Content Type Overview
content_type_overview.

.

drupal.org/project/content_type_overview
drush dl content_type_overview
(admin/modules).
, ,

( Ctrl+F Command+F)
(, ). Content Type Overview
Administration:
* ADMINISTRATION
ENABLED
gj

NAME

VERSION

DESCRIPTION

Content type overview

7.x -1.0-b e ta 2

Provides easy access to all basic content type settings.

OPERATIONS

Save configuration
. Drupal : The configuration options
have been saved ( ).
, Content type overview
, Drupal 7,
Operations . ,
.info, Modules.
drupal.org/node/1032930.
, .
Configuration (admin/config),
.

Ctrl+F:
A

Content

Find content

Structure
Add content

Appearance

People

Add Suggestion

Modules

Configuration

Reports

Contfgufc new content input oy users ts Iwefeo, frtctudsng asfoweo .


tags. Also allows enabling of module-provided filters.

DEVELOPMENT
; 0

MEDIA
; j j

Filesystem
Teti Drupal where to store uploaded files and now they are accessed.

Image styles
Configure styles that can be used for resizing or adjusting images on
display,

; ;fj

'Content type oveI[

Kelp

Author chapter list

image toolkit
Choose which image toolkit to use if you have Installed optional toolkits.

Performance
Enable or disable page caching for anonymous,users and set CSS and JS
bandwidth optimization options,
Logging and errors
Settings for logging and alerts modules. Various modules can route Drupal's
system events to different destinations, such as syslog, database, email,
etc.
Maintenance mode
Take the site offline for maintenance or bring it back, online.

fee* aM ^iew
Provides easy access to al! bask content type settings.

~\

116

4.

Development, , Drupal,
, .
admin/config/development/content_type_overview.
:
Home * Dashboard Configuration * Development

Content type overview

Content types
gjf Article
0 Chapter
0 Basic page

Point
Profile
Research question
Simplenews newsletter
0 Suggestion
Select the content types you warn to include on the overview page,
Shorten form labels
Enable this to shorten the form element labels. This makes it possible to display more widgets per screen.

Save configuration

Save configuration. !
? Drupal.
? ?
. , ,
Structure (admin/structure).
. , . , Content types (adm in/
structure/types). ! Overview:
Home * Dashboard * Structure

Content types

(admin/structure/types/overview). !
, :
CHAPTER

BASIC PACE

Name

Chapter

Basic page

Machine
name

book

page

Description

A summary or a list of headings for a

Use <em>basic pages </em> for your

Submission form settings


Title field
label

Chapter title

Title

j
Preview
before
submitting

Q Disabled
$ Optional
0 Required

Disabled
Optional
0 Required

CHAPTER

117

BASIC PACE

Explanation
or
submission
guidelines
Submit
again?

Publishing options

Default
options

gf Published
Promoted to front page
Q Sticky at top of lists
0 Create new revision

|Sf Published
Promoted to front page
Q Sticky at top of lists
Create new revision

! Create new revision


, , Promoted to front
page Published. , ,
,
, ,
, , ,
. 20 ,
Drupal 7.
, , ,
,
.
Masquerade
masquerade.

- . Masquerade

.



.
Panels
panels.
(merlinofchaos), Panels,

, .
Drupal,
, Panels Chaos Tools (ctools).
Code Filter
codefilter.
Drupal , ,
,
.

118

4.

,
.
1. Configuration Content authoring Text
formats admin/config/content/formats.
Filtered HTML
2. Enabled filters Code filter.
3. Filter processing order Code filter Limit allowed HTML tags.
4. Save configuration.

Limit allowed HTML tags Code filter,


HTML-, . , Limit allowed HTML tags
, Correct faulty and chopped off HTML .

Full HTML,
,
HTML- .
Colorbox
colorbox.
Drupal 6, Lightbox2, JQuery Lightbox
Thickbox, Colorbox JQuery ,
, -.



.
Menu block
menu_block.
, . ,
, .
,
.
.
Menu position
menu_position.
Menu position ,
. ,
, , 12
Blog ( )
,
.


Drupal ,
.
, -.

119

Comment notify
comment_notify.
Comment notify
.
Drupal .
Drupal.
Comment notify Token (drupal.org/project/token).
, . Drupal
, . 4.3.
Home Qmhbo&rd * list

Some required modules must be enabled


You must enable the Token module to install Comment Notify.
Would you like to continue with the above?
Continue

Cancel

. 4 .3 . Token,
Comment notify

Comment notify .
Configuration People Comment
notify (admin/config/people/comment_notify). ,

. ,
, .
Organic Groups
.
Organic Groups
.
. ,
, .
5.
Rate
rate.
Rate ,
Drupal 7.
Voting API
votingapi.
Voting API
,
. ,
. Fivestar (fivestar),
Voting API Drupal 6.
Userpoints
userpoints.

120

4.

Userpoints
, ,
.
Profile2
profile2.

, Drupal Field API.
Profile, Drupal ,
.
Role Limits
rolejimits.
Role limits ,
. , , ,

.

, 4 0 4
404.
Apache Solr
apachesolr.
Apache Solr ,
Drupal, .
, Drupal .
,
, ,
29.
Search 404
search404.
File Not Found
,
.


. 404
watchdog ( Database log,
admin/reports/dblog, Syslog,
). 404

Redirect.
, .
.
dgd7.org/fast404.

404 Navigation
navigation404.

121

, ,
Drupal.
File not found. 404 Navigation
Search 404.
Global Redirect
globalredirect.
Global redirect
.
, , .
, Global redirect
( Drupal 7
),
.


Drupal , :
, , , .
Bot
bot.
Bot IRC-. IRC,
, Drupal , Druplicon,
, 9.
OpenLayers
openlayers.
OpenLayers
Drupal.


,
,
Drupal.org .
,
.
, , Drupal .
, ,
. , ,
-. , - ,
Drupal , , , ,
!.

,
. , , , ,
dgd7.org/modules.

5. Organic Groups

Drupal
, , ,
. .
: (user), (member) (administrator).
Facebook
. , (visitors)
(contributors),
-.
Drupal...
. , .
Drupal.
Organics Groups.
.
Group .
, Blog, Events Aggregator,
.
, Group Manager Administrator. Organic Groups
, .
, ,
3 Views, Panels, .
Views , Panels
. ,
. Panels ,
.
. ,
, ,
, .
.
. Drupal ,
.
,
.
, Drupal 7
. , ,
, .


Organic Groups
Drupal 7, , ,
. Organic Groups Views.
, , : Organic Groups
Entity, Views CTools, .

Organic Groups

123

, Drupal 7
admin/modules/install. :

Organic Groups (drupal.org/project/og);

Entity (drupal.org/project/entity);

Views (drupal.org/project/views);

CTools (drupal.org/project/ctools).

Organic Groups Drupal 7 .


, , ,
. ,
.

Organic Groups , . 5.1.


Migrate,
.
ENABLED

NAME

VERSION

DESCRIPTION

API to altow associating content with groups.


Organic

7.X-1.X-

groups

dev

Requires: Entity APS (disabled}, Ust (enabled), (enabled), Reid SQL storage {enabled}, Options (enabled)
Required by- Organic groups access control {disabled*. Organic groups context (disabled), Organic groups Ui (disabled), OG example
(disabled), Organic groups field access (disabled). Organic groups migrate (disabled), Or ganic group* register (disabled)

Organic
groups access

control

Organic

7 .x-1.x-

groups context

dev

Organic
groups field
access

7 ,x-l.x~

dev

Organic

7,x-l.x-

groups migrate

dev

Organic

7.X-1.X-

dev

7.x-1.x -

Enable access control for private and public groups and group content.
Requires: Organic groups (disabled), Entity API (disabled), Ust (enabled}' field (enabled)., field SQL storage {enabled}, Options
(enabied)

Get a group from a viewed page.


Requires: Organic groups (disabled). Entity APf (disabled), Ust (enabled), Field {enabled.). Field SQL storage (enabled). Options
(enabled)

Provide field access based on group.


Requires: Organic groups (disabled), Entity APf (disabled), Ust (enabled). Field {enabled}., Field SQL storage (enabled). Options
(enabled)

Migrate Organic groups data.


Requires: Organic groups (disabled). Entity API (disabled), Ust (enabled). Field (enabled), Field SQL storage {enabled}, Options
(enabSed), Chaos tools (disabled)

Allow subscribing to groups during the user registration.


Requires:. Organic groups (disabled), Entity API {disabled), Ust (enabled), Field (enabled), Field SQL storage (enabled). Options

groups
register

dev

Organic

7.X-1.X-

Requires : Organic groups (disabled). Entity APS (disabled), Ust (enabled), field (enabled), Field SQL storage (enabled), Options

groups Ui

dev

(enabled)

{enabled)

Organic groups UI.

Required by: OG example (disabled)

. 5 .1 . Organic Groups

OG access control
. Yes, .

OG Example, . 5.2.
Features. ,
Features UI (structure/features).
Modules
, (. 5.3).

124

5. Organic Groups

example

Example module to show Organic groups configuration that can be used as building
block.
Requires: Chaos tools (enabled), Features (enabled), Organic groups (enabled). Entity API

7.x- 1.xdev

(enabled), List (enabled), Field (enabled), Field SQL storage (enabled), Options (enabled),
Organic groups Ul (enabled), Page manager (enabled), Panels (enabled), Views content panes
(enabled), Views (enabled)

. 5 .2 . OG Example

Home Administration Modules

You must enable the Features, Page manager, Panels, Views content panes modules to install OG example.
Would you like to continue with the above?
Continue

Cancel

. 5 .3 . , OG Example

Group
Drupal :
Basic page. OG Example : Group
Post, . 5.4.

Article

Article
Use articles for time-sensitive content like news, press releases or blog posts.

| Basic page
Use basic pages for your static content, such as an 'About us' page.

Croup
The group that will have members and content associated with.

post
Content that will belong to a single or multiple groups.

. 5 .4 .

Group Post,

OG Example

Group , Post
, .
. Structure Content
types Group (admin/structure/types/manage/group).
:
Name Group.
Description Create a new group ( ).
Publishing options Promoted to front page.
Display.
Comment settings Closed.
, . 5.5.

125

Organic Groups

Hom * Administration Structure * C om em types

GrOUP O

edit

Name *
Group

Machine name: group

The humarweadabSe name o f this comen? type. This text w ill be displayed as part of the list on the Add new content page, it is recommended that this
name begin with a capital ietter and contain oniy letters, numbers, and spaces. This name must be unique.

Description

Create a new group.

Describe this content type. The text wifi be displayed on the Add new content page.

Subm ission form settings

Specify how Croup should treat content of this type. Content may behave as a group, as group
content, or may not participate in Croup at ail.

Group Name

Publishing options

Croup

Published

Q Not a group type

Display settings
Don't dispiay p ost information

@ Group type

Com ment settings

Set the content type to be a group, that content w*ii be associated with, and wili have group members.
To unset the group definition you should delete the "Group type" field via Manage fields.

C losed, Threading , 50 com m ents per


page

Group content

Menu se ttings

0 Not a group content type

Croup

0 Group content type

. 5 .5 . Group

, Group
OG. ,
. Group
, Group type.
.
Group Manage Fields. edit
Operations Body, Mission statement ( ),
. 5.6. ,
.
,
.
WIDGET

OPERATIONS

Boolean

Check boxes/radio buttons

edit

delete

Long text and summary

Text area with a summary

edit

delete

LABEL

NAME

FIELD

Group Name

title

Node module element

*>

Group type

group_group

*$f

Mission statement

body

. 5 .6 . label Group content

Manage Display, .
.
Format Group type Group subscription,
. 5.7. .

126

5. Organic Groups

uvea

FIELD
4

FORMAT

Croup type

<HWden> i

Mission statement

<> *

lio u p J

. 5 .7 . Manage Display. Group type Group subscription


Join


, Group content, .
Add content
. Group (node/add/group).
iPad- iPad Users Group. Mission Statement ,
. 5.8 .

Social Seniors Community



Home

iPad Users Group


View

Ij

Edit

Group

Group type:
You are the group manager
Okay, You got a great gift from your children. Now what?
Join this group and find out, thats what!
. 5 .8 . iPad Users Group

, Group,
, You are the group manager
( ). ,
, Request group membership ( ).
Group ,
. .
,
Views Panels.

Views
Organic Modules
OG , . 5.9.
.

Views Organic Modules

VIEW NAME

DESCRIPTION

content

Show all content (nodes) of a

None
In code
Type: Content

group.

OG list

Show active groups that are


nodes

Displays: Feed, Page

| TAG

: PATH

OPERATIONS

group

group

127

group-list, group-list/feed

edit

*>

edit

edit

In code
Type: Content
Newest group members.

members

Display: Block
In code
Type: User
Show groups of a user.

User groups

default

user-groups

edit

Display: Page
In code
Type: Content

. 5 .9 . ,
OG

OG List ,
.
(group-list), , . 5.10.
,
.
Feed

edit view name/description

+A dd

^ details
Display nam e'

TITLE

PACE SETTINCS

Title: Croups list

Path: group-list

A dvanced
CONTEXTUAL FILTERS

Menu: No menu

FORMAT

FIELDS

Group: Node group


add

HEAOER
FOOTER

Content: Title (Title)


(group) Organic groups group: Created
(Since)

PACER
Use pager:

FILTER CRITERIA

RELATIONSHIPS

Access: None

Format: Table i Settings

EXPOSED FORM

Page: Menu Item entry

(group) Organic groups group. State (


Active)

No menu entry
Normal menu entry

SORT CRITERIA

NO RESULTS BEHAVIOR

,dd

Menu tab
Default menu tab

T itle
Groups

if set to normal or tab, enter the text to use


for the menu item.
Description
If set to normal or tab. enter the text to use
for the menu item's description.

insert Item into an available menu.

. 5 .1 0 . Group-list

menu Page Settings


. Groups
, . 5.11.

Groups.

128

5. Organic Groups

My account Log out

Social Seniors Community

Home

Groups list

j Since

14mtn56secago

iPadUsers Group

m
. 5 .1 1 .

,
,
.


- , ,
.
Post, OG Example.
, , . 5.12.
Modules (admin/modules).

Blog

7.0

Enables multi-user blogs.


Required by: Flexible blogs (disabled)

. 5 .1 2 . Blog

Blog (admin/structure/types/manage/blog)
Group content type, . 5.13.
, ,
.
Submission form settings
Title
Publishing options
Published , Promoted to front page

Specify how Croup should treat content of this type. Content may behave as a
group, as group content, or may not participate in Group at all.
Croup
Not a group type

Display settings
Display author and date information.
Comment settings
Open, Threading , SO comments per
page
Menu settings

Group type
Set the content type to be a group, that content will be associated with, and will
have group members.

Croup content
Not a group content type

Croup

@ Group content type


Set the content type to be a group content, that can be associated with groups.
To unset the group content definition you should delete the "Groups audience" field
via Manage fields.

. 5 .1 3 .

129

,
, iPad-. (
node/add/group) Tee-Birders Golfing Group,
( node/add/blog) (. 5.14).
Home Yes, that was in that sandtrap

Title *____________________
iYea, that was ms In that sandtrap

Groups audience
My groups
Pad Users Group
Computer Help Group
Pottuck Dinner Group

: nirrf nrtfar Qrtufi


Select the groups this content should be associated with.

Body (Edit summary)________________________________________________________


The reports you heard on the news about a sandstorm blowing in from the northeast was simply
;me trying to get out of the sandtrap on the fifth hole at Long Acres.
In case you're wondering, I did eventually make it to the green.

. 5 .1 4 . ,
Group audience,

(. 5.15). ,
. 5.16, , Panels
.

. 5 .1 5 . Tee-Birders Golfing Group

130

5. Organic Groups

My account

Log out

Social Seniors Community

Home

The Tee-Birders Golfing Group


f View jf Edit

|| Group

You are the group manager


Golfing group for seniors who aren't afraid to go over a hundred. Outings, three times a week, on
Tuesdays, Thursdays, and Sundays.

. 5 .1 6 . Tee-Birders Golfing Group

Panels
Panels
Panel.
Structure Pages (adm in/structure/pages) ,
Node template, . 5.17.
OG Example.

TYPE

j NAME

!m u

f PATH

STORAGE

OPERATIONS

Edit
Enable

System

nodeedit

Node add/edit form

/node/%node/edst

in code

System

node_vlew

Node template

/node f%node

In code

System

termview

Taxonomy term template

/taxonomy/term/%iaxonomyjerm

In code

Edit
_ .4
Enable

System

userview

User profile template

/user/^user

in code

Edit
Enable

Edit
Disable

. 5 .1 7 . OG

,
. 5.18. :
( );

;
.

Panels

My account

131
to g out

Social Seniors Community

-Bird Golfers Group


; View | j Edit ii Group ;

+ Edit Panel
So you haven't broken a hundred in awhile? Along while? No worries, neither have any pf us. But we have a lot
of fun trying.
Join us.

Group articles

Content create links

Yes, that was me in that sandtrap

Post

Submitted by 007 on Thu, 04/28/2011 - 16:13

The reports you heard on the news about a sandstorm

M e m b e rs

blowing in from the northeast, was simply me trying to

007

get out of the sandtrap on the fifth hole at Long Acrcs.


You are the group manager
In case you're wondering, I did eventually make it to
the green.
Read more

. 5 .1 8 . Panels

Edit panel
, . 5.19.
.

Node template
j Disable j Add variant j Import variant

Summary

Variants Group Summary

Variants

Variant operations

Group

Clone j Export | Disable

Get a summary of the information about this variant.

Summary
General
Selection rules

..... ]

Storage

In code

Status

Enabled

Disable

Selection rule

This panel wiH be seiected if Node being viewed exists.

Edit

Layout

Two column stacked

Contexts
Layout
Content
Preview

Change layout
Edit content
Preview

. 5 .1 9 . OG Example

132

5. Organic Groups

Selection rules, ,
, Layout, ,
. :
Selection (. 5.20);
Layout (. 5.21);
Content (. . 5.22).
TITLE

DESCRIPTION

OG: Node is a group

Node being viewed exists

l l l l l
m

. 5 .2 0 . Selection.

__

Single iolumn

Two column

Two column
bricks

Two column
slacked

Three column

Three column

Three column

25/50/25

25/50/25

33/34/33

. 5 .2 1 . . Two column stacked

Summary

Variants Group Content

Variants

Variant operations

Croup

| Clone ] Export J Revert j Disal

Add content items and change their location with a drag and drop interface.

Summary

Title type

General
Selection rules
Contexts

Title

Layout
Content
Preview

,
j

The title of this panel, if left blank, a default title may be used. Set to No Title if
you want the title to actually be blank. You may use substitutions In this title.

SUBSTITUTIONS

Top

i * No Info


(
)

Left side

(X. nntk".

| *. nt onI (

No title

Right side
link'.

No Info
1 (,K. rvomluM s

!<

j * No title
j " \ 0 ( ! p l)t MUJ VI o v v e i i '

No Info

Bottom
. 5 .2 2 .

133

Panels , ,
. ,
, drupal.org/node/496278.

,
, ,
,
. (admin/config/group/roles), . 5.23,
(admin/config/group/permissions)
. 5.24.
NAME

OPERATIONS

non-member

locked

edit permissions

member

locked

edit permissions

administrator member

edit role

edit permissions

Add rote

. 5 .2 3 . ,

PERMISSION

NON-MEMBER

MEMBER

ADMINISTRATOR MEMBER

Organic groups
Edit group

Edit own Post content

Edit any Post content

Delete own Post content

Delete any Post content

Edit the group, 'tote: This permission controls only node entity type groups.
Administer group
Manage or bsock users, and manage their rote assignments in the group.

Organic groups field access


View Comment field
View the Comment field for existing groups.
Edit Comment field
Edit the Comment field for existing groups.
View Body field
View the Body fieid for existing groups.
Edit Body fieid
Edit the Body field for existing groups.

. 5 .2 4 . ,

Organic Groups Drupal 7 ,


drupal.org/project/og.

134

5. Organic Groups

Drupal 7 ,
Organic Groups ,
, . ,
Views Panels .
,
,
.

6. Drupal

, .
,


.

, ,
.
, , ,
,
. ,
, . ,
Drupal- ,
.

Drupal
: Drupal !
, .
. -
, . ,
Drupal 7 ,
.
;
Drupal.


,
(. 6.1). , ,
. 1
.
Password

Password strength:

Fair

Confirm password

j To make your password stronger:


i Add uppercase letters
j Add numbers
| Add punctuation
. 6 . 1 .

136

6. Drupal

www.baekdal.com/tips/password-security-usability ,
, , (,
Drupal ).
.
. ,
,
( );
.
, .
, , ;
,
Drupal, .

1
, ,
. 1
. Drupal
. ,
, : , example@
gmail.com , example+site 1@gmail.com, Drupal
.

Drupal 6 1
update.php settings.php. Drupal 7 update,
php .


,
. ,
, .
, Administer,
.
(Bypass content access control) ,
, .
Drupal 7 , . 6.2.
PERMISSION
............................... ..................... .......... _ ___ '....... .........................______;....J

USER

USER

ADMINISTRATOR

Administer content

Warning: Give ft? trusted rotes onty; this permission has security implications.

. 6 .2 . ,

, (Authenticated User)
, , .
Drupal ,
.
admin/config/people/accounts

Drupal

137

, , Authenticated User, ,
. ,
.
(Post comments)
(Skip comment approval).


. ,
, , Drupal
. ,
,
.
Safe String Theory for the Web acko.net/blog/safe-string-theory-for-the-web.

: (Cross-Site Scripting, XSS)1. Drupal
( ) .
,
. Filtered HTML Plain Text
, , ,
. ,
.
Security Review2.

PHP Filter
PH P- Drupal, ,
, ! PHP-
. , :
( ,
, ).
, .
, ,
-.
-.
PHP Filter ( ),
Drupal.
-
.

PHP Rlter, .
- drupal.org
: ,
.
. , ,
, .
1 http://ru.wikipedia.org/wiki/Cross-site_scripting
2 http://drupal.org/project/security_review

138

6. Drupal



. , Drupal,
, .
, .
, .
Drupal, -.
Drupal Security Team ,
Drupal ,
.
Drupal .
,
.
(Security Advisories, SA)
, . S-
, . SA-.
SA- Drupal (, SA-CORE-2010-002)
, Drupal.
.
SA- (, SA-CONTRI6-2010-015)
. (
).
.
(, PSA-2011-001)
,
,
, ,
.
SA- :
, , Drupal.org drupal.org/security.
RSS- :

drupal.org/security/rss.xml;

drupal.org/security/contrib/rss.xml;

drupal.org/security/psa/rss.xml.

; .
My newsletters
Drupal.org.

twitter.com/drupalsecurity.

SA-
. ,
. ,
,
. PSA
.


Drupal ,
; ,

139

. Drupal.
org . Drupal-

,
-
, .
.
Drupal.org , ,
.
, ,
.
- Drupal-,
.
.
, , ,
;
.

,
. , .
drupal.org/project/views. 6.3 6.4
.
.
. ,
Drupal.org . ,
,
.
, .
. ?
.
. 6.3. , ,
, , .
, ,

, ,
.
Project Information
Maintenance status: A Abandoned
Development status: A Obsolete
Module categories: Administration , Content, Location , Utility
. 6 .3 . Project Information

. , ,
Project Information, . 6.4. ,
.

140

6. Drupal

Project Information
Maintenance status: Actively maintained
Development status: Under active development
Module categories: Content Display , Views
Reported installs: 271070 sites currently report using this module.
Last modified: January 18, 2011

. 6 .4 . Project Information

. (development
releases). .
, - -
; .
- ,
.
.
Issues,
. . 6.5. open
issues,
(. 6.6).

Issues for Views


avoid duplicates, please search before
submitting a new issue,

\ {^Search J
Advanced search

870 total
Bug reports
32? open, 4438 total
Subscribe via e-m ail
Issue statistics
Oldest open issue:

2 Apr OS

. 6 .5 .

,
. Last updated ,
(. . 6.6).
Fixed .

, .

, ,
, ? ,

141

,
.
, Drupal,
Coder1 Secure Code Review2. ,
.

.
,
, . Drupal Scout (drupalscout.
com) (Greg Knaddison) (Ben Jeavons),
, Drupal.
Summary

Status

Priority Category

Version

Component

Replies Last
updated '

exceedingly minor css syntax cleanup: extra


sem i-colon new

active

minor

bug
reports

6.-22

M iscellaneous

10 min 3
sec

Conditional Fields new

needs
work

normal

feature
requests

6.-22

User interface

25 min
2 8 sec

Panel Field not working after upgrading


Views 2,11 to the version o f 2,12 new

active

normal

bug
reports

.-2.12

M iscellaneous

2
2 new

41 min
47 sec

Better contextual link integration for blocks


updated

active

normal

tasks

? .x -3 .x -d e v

User interface

4
1 new

1 hour 5
min

Problem making a seach in a view in a


multilingua* site new

active

normal

bug
reports

. - 2 .8

Miscellaneous

1
1 new

1 hour
14 min

* 6 .6 . ,


Drupal
. Drupal -
, .
, , , . ,
,
Drupal. ,
Drupal-
.
Drupal Update Manager,
.
. .

Report Available updates (admin/reports/updates). , ,
, . 6.7.

1 http://drupal.org/project/coder.
2 http://drupal.org/project/secure_code_review.

142

6. Drupal

Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of
a "projectwhich may or may not have the same name, and might include multiple modules or themes within it.
Install new module or theme
Last checked: 0 sec ago

(Check manually)

Drupa! core
Drupal core 7.0

Up to date

Includes: Bartik, BlockColor, Comment, Contact, Contextual finks, Dashboard, Database logging, Field, Field SQL storage, Field

UI, File, Filter, Help, Image, List, Menu, Node, Number; Options, Overlay, PHP fitter, Path, Poll, RDF, Search, Seven, Shortcut,
Statistics, System, Taxonomy, Text, Toolbar, Update manager, User

Modules
Address Field 7 .x -l.x -d e v (2 0 1 1 -Jan-IS)

Update available

Recommended version.*

7.x-1.0-alpha 1 (2O1O-Oct>09)

Download
Release notes

Development version;

7.x~l.x-dev (2011-Feh-25)

Download
Release notes

Includes: Address Field

. 6 .7 . Update Manager
. ,

Drupal . Update Manager


-. Drush1,
, tarball , git.
7.


Drupal .
,
. ,
. ,
Drupal , ,
. :
HTML-,
<> h re f, ,
. 1()2,
, Drupal .
1 http://drupal.org/project/drush.
2 http://api.drupal.O rg/api/function/l/7.

143

Form API. $_POST,


Form API,
1.
Database API. SQL- PH P-,
SQL-2. ,
Database API3.
, Drupal
.
,
Drupal.
:
(Greg Knaddison), , Drupal,
, : Cracking Drupal: A Drop in the Bucket (Wiley,
2 0 0 9 ), crackingdrupal.com.

Drupal, (Ben Jeavons)


(Greg Knaddison), drupalsecurityreport.org.
, , ,
, .
:
Drupal api.drupal.org,
API. ,
.
Develop for Drupal
Drupal API. drupal.org/documentation/develop.
Writing Secure Code Develop for Drupal
, Drupal API.
drupal.org/writing-secure-code.
:
(Heine Deelstra), , Drupal,
, , heine.familiedeelstra.com.
(Greg Knaddison) (Ben Jeavons)
crackingdrupal.com/blog.
DrupalScout , ,
drupalscout.com/knowledge-base.


, Drupal,
Drupal.org. ,
, ,
.
1 http://ru.wikipedia.org/wiki/Cross-site_request_forgery.
2 http://ru.wikipedia.org/wiki/SQL_injection.
3 http://drupal.org/developing/api/database.

144

6. Drupal

Drupal
; ,
,
Drupal drupal.org/security-advisory-pollcy.
-, , Drupal.org; ,
Drupal, ,
. -, ( ,
, , - -
), .
(, 7.x-1.2), ,
, , :
(Administer filters);
(Administer users);
(Administer permissions);
(Administer content types);
(Administer site configuration);
(Administer views).
, , ,
, ,
.
drupal.org/security-advisory-policy. .
,
, (security@drupal.
org), , , Drupal,
.
. , , .
, ,
, , , ,
drupal.org/node/101494.
,
.

, ,
.
. ,
, .
,
. ,
, , .
SA- .
. .
Drupal.
org 24 .
, , Security
update, . 6.8. ,
SA-.
SA- .

145

Create Project release


Now that the tag has been selected these can not be modified unless you 90 back to the previous page.
Git tag: *

h--

Version string:=
7.X-L5

Core compatibility: *

f'
Releasetype:
j - None -

; qtmrnmimmm*"*"-

\ Bug fixes
New features
What is a reiease type?

Are you sure you want to mark this release as a Security update?
if you select Security update, your retease will not be published without the manual intervention of the Drypai Security Team. Vou should have already contacted she Security

Team to coordinate a security advisory sSA) for your release before you committed any security-related patches.
( Spfit summary at cursor j

Retease notes:

Fixes SQL injection issu e .

. 6 .8 . Create Project release Drupal.org.


, Security update

, , ,
, .
Security update, . 6.8,
.

,
Drupal, Drupal-
, . ,
Drupal API
. !

7. Drupal

,
, .

-
Drupal 7 , .
(minor version update). Drupal
7 .2 7.3.
.
Drupal 7 7 . -2 .1 1 7 . -2 .1 2 . ( Drupal
, . ,
: 7.1, 7 .2 ,... 7.8, 7.9, 7 .1 0 , 7 .1 1 .)
(major version upgrade)
. , Drupal 6 Drupal 7,
Drupal 7;
;
, . ,
. Drupal 7
- 7 - API .
, ,
.


Drupal . .
-, . -,
.
,
(drupal.org/security-team) Drupal
.

.
.
, ,
Drupal,
; ,
. ,
, 6.

, Drupal, .
Drupal 7.

Drupal 7 ,
( Drupal 9).

147

drupal.org
.
. Openflows Community Technology
Lab
Drupal (http://openflows.com/drupal/security).

. , , Drupal. -,
Drush-. , ,
.
,
Drupal, ( ;
, .htaccess ).
, .
.
,
.

Drupal - .
:
/ .
.

, ,
. AWStats (awstats.sourceforge.net) Google
Analytics ( drupal.org/project/google_analytics).

. ,
.
(, 7.0 7.3)? . Drupal.
org Download & Extend, Drupal core (drupal.org/project/
drupal), View all releases (
drupal.org/node/3060/release).

, , .
, Reports Available updates (admin/
reports/updates). , , ,
- . Drupal ,
, .

, .
Git, git status, Drupal-.
( , git pull.)

.
php MyAdmin Drush :
mysqldump -u exampleuser - examplepass example > example_backup.sql

148

7. Drupal

Backup and Migrate drupal.org/project/

backupmigrate.


UPGRADE.txt,
Drupal.
Drupal. ,
, .
, .

,
. , , ,
Drupal.

Drupal : .
, sites.
, : .htaccess robots.txt. ,
, ,
.
sites ( , , ),
.
, Drupal,
( , 7.1;
):
cd ~/code
wget http://ftp.drupal.org/files/jects/drupal-7.1.tar.gz
tar -xzf drupal-7.1.tar.gz

Drupal Drupal.org (drupal.org/

home).

UPGRADE.txt
UPGRADE.txt.
, .
1.
(Administer software updates).
, user 1.
2. Configuration Development Maintenance
mode (admin/config/development/maintenance). Put site into maintenance
mode Save configuration. Maintenance mode message
, .
3. codebase .
sites, .htaccess robots.txt. ,
, -. ,

149

dif f . ,
sites.
. codebase sites
, .htaccess robots.txt.
.
Drupal example/web:
mv example/web examplewebtmp/
mkdir -p example/web
cp -pr examplewebtmp/sites/ example/web/
cp examplewebtmp/.htaccess example/web/
cp examplewebtmp/robots.txt example/web/

4. Drupal codebase,
sites .
sites.
Drupal install:
cp -R drupal-7.1/* drupal-7.1/.htaccess example/web/
rm example/web/sites/default/default.settings.php

5. .htaccess robots.txt.
, settings.php, .
, ,
d if f . .htaccess ,
. robots.txt. settings.php
default.settings.php.
diff
:
diff -up example/websites/default/settings.php/
example/web/sites/default/default.settings.php
diff -up example/web/robots.txt drupal-7.1/robots.txt
diff -up example/web/.htaccess example/web/.htaccess

d iff , settings,
php. robots.txt .htaccess
, , . + ()
, , - ()
, .
.

, Drupal,
,
diff , .
.

6. update.php, http://example.localhost/update.php ,
http://example.com/update.php .
, ( ) .
,
update.php . Continue.
, No pending updates, . 7.1.
- , .

150

7. Drupal

Drupal database update

No pending updates.

Front page
Administration pages

v ' Verify requirements


V Overview
Review updates
Run updates
Review log

. 7 .1 .

7. Reports Status report (admin/reports/status)


,
Drupal. , ,
, watchdog ( Database logging,
admin/reports/dblog, Syslog
syslog).
8. ( UPGRADE.txt 8)
,
$ u p d a te _ f ree_access settings.php TRUE. ,
.
9. Maintenance mode (admin/config/development/maintenance)
Put site into maintenance mode. Save configuration.

, , 1 2
( ),
6- 9-. 13.

Drush
Drush .
. drush
pm-update drush up.
,
. ,
, drush upc,
, .
drush updatedb ( ) ,
drush updated (
update.php).

.
Drupal Drush drush up d ru p a l.
Drush 25.

diff

151

diff
, . ,
Drush-, , ,
. !
7.1 ,
Drupal,
. ,
Drupal, ,
.


diff Hacked (drupal.org/project/hacked).
, , .

git.drupal.org.
,
. , dgd7.org/update!
, , 7.1.
7 . 1 . Drupal

#!/bin/sh -
if [ $# -It 2 ]; then
echo "Usage: $0 oldversion newversion (optional) directory (e.g. 5.5 5.6 dir)"
exit 1
fi
# , - !
TMP=/tmp
#
VER_0LD=$1
VER_NEW=$2
if [ $# -gt 2 ]; then
DRUPAL_DIR=$3
else
DRUPAL_DIR=' pwd'
fi
# Drupal
PATCH_FILE=$TMP/drupal-$VER_OLD-to-$VER_NEW.patch
cd $TMP
#
wget http://ftp.drupal.org/files/projects/drupal-$VER_OLD.tar.gz
#
tar -xzf drupal-$VER_OLD.tar.gz
#
wget http://ftp.drupal.org/files/projects/drupal-$VER_NEW.tar.gz
#
tar -xzf drupal-$VER_NEW.tar.gz

&

152

7. Drupal

#
# echo " ,
."
echo diff -Naur $TMP/drupal-$VER_OLD $TMP/drupal-$VER_NEW > $PATCH_FILE'
# Drupal
cd $DRUPAL_DIR
#
set -vx
#
patch - --dry-run < $PATCH_FILE
#
set +vx
# ( - , - )
echo "If the above dry run patch applied without errors, you can press Y to apply the
patch for real."
echo "If there are errors, or you just aren't ready to apply the patch, press N to
abort."
read YN
if ( test -z "$YN" )
then
echo -e "Please enter either \"Y\" or \"N\" " ;
eval "$0" "$@" ;
exit ;
fi
# 'YN' Y, y, N n
if ( test "$YN" = "N" -o "$YN" = "n" )
then
exit ;
fi
set -vx
# , ,
#
patch - < $PATCH_FILE

,
Drupal. upgrade,
:
/path/to/version-upgrade-diff.sh 7.0 7.1

scripts, dgd7
code Drupal , :
~/scripts/version-upgrade-diff.sh 7.0 7.1 ~/code/dgd7/web


.
, , Reports Available
updates (admin/reports/updates), .
, ;
,
Includes, . 7.2.

Image Resize Filter 7.-1.12

153
Up to date /

Includes: Image resize fitter


Insert 7jc-1.0

Up to date

includes: Insert
LoginToboggan 7.X-1.1
Recommended version;

Update available &

7.x-1 2 (2011-Apr-06)

D ow nload
R e le a s e n o te s

includes: LoginToboggan, LoginToboggan Rules Integration


Pathologic 7.X-1.1

Up to date

>/

includes: Pathologic

. 7 .2 .


. update.php .
, http://example.localhosVupdate.php http://example.com/
update.php . -
, .
,
. ,
.
13 ()
25 ( Drush).

. ,
. , , 2.x
3.x,
. .
Drupal.
org .
(
).


Reports Available updates Update (adm in/
.
, ,
Download these updates, . 7.3.
,
.
. Drupal ,
( , Drupal
, . 7.1).
Drupal
, .
.
reports/updates/update).

154

7. Drupal

Download these updates

. 7 .3 .
,

Drupal
(, FTP,
), .
Drush.

Drush
Drush ,
Drupal. Drush
: , .
Drush 2.
25.
,
, Drush ,
(drupal.org/node/1002658). .
, Drush (-
-
) . ,
Drush
.
,
. ,
, ,
Drush ,
CTools Views drush upc c to o ls views.
, ,
Reports Available updates (adm in/reports/updates).
, , Drush-. (
drush up ,
() .)
, LoginToboggan ftp.drupal.org/files/projects/
logintoboggan-7.x-1.2.tar.gz, , , :
drush up logintoboggan

.
Meta tags nodewords.

Image resize filter image_resize_filter,

155

,
, :
drush up logintoboggan-7.x-1.2

.
Drupal
! , Drupal
.

.
dgd7.org/update,
.

8.

,
.

1 Drupal, 3
Views, 4
. ,
,
,
.


, , ,
. ,
,
. Author Profile ,
.

, ,
. , .
.
, ? Drupal
, , . ,
, ,
,
? , Profile2 (drupal.org/project/profile2),
, .
, .

, .
1. , 1, .
Structure Content
types Add content type (admin/structure/types/add).
2.

Author profile edit


.
a u t h o r _ p r o f ile p r o f il e .

3.

Submission
form settings Title field label Title Name, . 8.1.

Submission settings

Titla field label *

Name

Name
Publishing options______________j_____ "

. 8 .1 . Author;
Name

157

4. Publishing options Create new revision,


, , .
5. Display settings Display author and date information,
. 8.2.

Q Display author and date Information.


Author username and publish date will be displayed.

Length o f trimmed content


600 characters

Comment settings
Open, Threadmg . SO comment* per p*ge

The maximum number of characters used in the trimmed version of content.

Menu settings

Save content type

Delete content type


. 8 .2 . ,

6. , , Comment settings
Hidden ( ) Closed (
). , ,
.
, , ,
Save and add fields.
Manage fields.



Drupal 7. Add new field :
Headshot;
headshot;
Image.

image. Drupal 7

, ,
, , ,
, .
. ,
. , ,

, .
.
, ,
(Author profile settings), headshot
. , Number of values
Headshot field settings 1. , ,
, .

158

8.


, , definitivedrupal.org
(
Drupal ).
,
Link (drupal.org/project/link). URL Drupal 4.7 . URL-,
Link ( ), CSS-
. ( ,
.)
Link,
. 4;
Drush (. 2 25).
Git (. 2).
drush dl link
Project link (7.x-1.0-alpha2) downloaded to
[success]
/home/ben/code/dgd7/drupal/sites/all/modules/link.
git add sites/all/modules/link/
git commit -m "Link module for link fields."
drush en -y link
The following extensions will be enabled: link
Do you really want to continue? (y/n):
link was enabled successfully, [ok]

Link
( Ctrl + F) Fields.

Link
. ,
. :
1. Structure Content types.
2. Manage fields Author profile,
admin/structure/types/manage/profile/fields.
3. Add new field.
4. Label Web site, website
( field_ ),
Link, . 8.3.
Configure,

Add new field


! ,

W e b site

Label
4*

fietd_ w ebsto

Field name (a-z. 0 -3 , J

Label

Field to share

F,oal

1
1

im age
Integer

Save

f - S e l e c t w ttg e T H '? !

Form elem ent to edit the data.

} Hie

Add existing field


* Select an existing Srtd -

I - Select a field type Boolean


Decimal

- Seiect a widget-

Form elem ent to edit the data.

List (float)
Ust (integer)
list (text)
Long text
Long text and summary

. 8 .3 . Link

159

5. Link (
).
, . Save.

Save, ,
/. ,
, Manage display.
Optional URL , , Link
.
Optional title Link title.
7. URL Display Cutoff 120 ,
, .
8. Link Target Default,
.
.
9. Rel Attribute .
, r e l ,
, , .
nofollow ,
, . Additional CSS Class
, - .
10. Save.
,
Profile settings ( Profile)
Web site field settings ( , ).

, . Number of values
Web site field settings, . 8.4.
, .
6.

WEBSITE FIELD SETTINGS


These settings apply to the Web site field everywhere it is used.
Number o f values
Maximum number of values users can enter for this field
'Unlimited* wit! provide an Add more button so the users can add as many values as they like.

. 8 .4 . Web site

Link
, ,
, . ,
, .
Web site,
.
. ,
. Drupal Manage fields Profile,
, .

160

8.


,
(
drupal.org, groups.drupal.org ). ,
Link, ,
.

drupal.org
Link. 30, ,
.

Integer.
Drupal. ,
: :

Drupal.org User ID, do_uid:

Groups.Drupal.org User ID, gdo_uid (,


field_).
Field settings ,
.

, drupal.org/node/552604
.

in te g e r,

. ,
.
.
, Structure Content types
Author profile Manage fields.
admin/structure/types/manage/profile/fields/field_gdo_uid
Groups.Drupal.org user ID. Prefix Suffix
. HTML-,
.
Custom Formatters (drupal.org/project/
custom_formatters). ,
HTML-.
,
(
) (,
Drupal.org).
30.

,
.


Author profile. .

161

Approximate Pages
integer,
, .
(. ).
, ,
. , integer, .


,
.
1. Drupal
.
References (drupal.org/project/references). :
drush dl references
Project references (7.x-2.x-dev) downloaded to [success]
/home/ben/code/dgd7/drupal/sites/all/modules/references.

references : node_reference user_reference.


git add sites/all/modules/references
git commit -m "Added project references (
node_reference, user_reference)."

2. User reference ( Node reference,


).
3. , Label DefinitiveGuide.org account
user. User
reference.
: Select list, Check boxes/radio buttons Autocomplete text field,
. 8.5.
4>

Add new field


DeftatVeGuide.or

label

field_ user

Retd nain (a-z, 0 -9 , J

User reference
Type of data to store.

/ Select list

Check boxes/radio buttons


Autocomptete text field

. 8 .5 . User reference

, , Check boxes/radio
buttons . ,
. Select list
.

4. ,
Autocomplete text field.
, .
, ,
, , , .
Select list
.

162

8.

5. ( Author profile,
Manage display) .
.
6. , ,
.
, author, , ,
, Active, . 8.6.
User roles that can be referenced
0 authenticated user
Q administrator
author
trusted

User status that can be referenced


0 Active
Blocked

Save field settings

. 8 .6 . ,
7. Save field settings .
8. . ,
. ,
, .
Save settings.


1,
.
Drupal. People Permissions
(admin/people/permissions).

Author profile: Create new content Author profile: Edit own content,

.

Administrator ,
, , Node Bypass
content access control.

,
Administer content type Access the content overview page, Administer comments
and comment settings Bypass content access control.
dgd7.org/content.
, , .

163

, Add new content


Author profile (node/add/profile).
, ,
- ,
.
Masquerade (drupal.org/project/masquerade).


, . Authoring information,
/ , Authored by admin ,
. ,
.

, , ,
People Add user (adm in/
people/create). . ,

.
, dgd7.org/moresite.


, ,
. , , .
:
, , ,
.
.
, , .

.
,
. .
Views.

Views Drupal 7
Entity Field Query Drupal. dgd7.org/180
, Views
.


Views ,
.
, .
1. Structure Views
Add new view (admin/structure/views/add).

164

8.

2. . View name Author profiles,


profiles.

3. Description ^
, view to show ail the author profiles (
).
4. .
Show Content ( ), of type
Author profile.
5. Create Page title,
, Authors.
. URL- authors. Display
format Grid of fields,
.
6. Continue & edit. .
, , . ,
, ,
. .
, Grid settings Number of columns 4.

(. 15 16, dgd7.org/theme
) .
Format HTML List ,
. , , Drupal
, .

Fields Add,
. . Authors
,
. Content: Image (,
author profile?) Content: Title.
8. Content: Image
( Create a label), Image style
thumbnail, .
Link image to Content. Content: Title
Link this field to the original piece of content.
9. !
,
( ),
4 . ,
.
7.


, . ,
, .
.
, image,
.

165

, , , Drupal
.
, , ,
. Image styles
Scale Crop.
Drupal ? ! Smart Crop (drupal.org/project/
smartcrop) .
.
, .

Smart Crop Drupal ,


. ,
, Imagefield crop (drupal.org/project/
imagefield_crop),
.

10. (
edit). , ,
Add style, . 8.7. Image
, , ,
, .
, ,
, ,
.
Home Administration * Configuration Media

Image styles

Image styles commonly provide thumbnail sizes by scaling and cropping images, but can also add various effects before an
image is displayed. When an image is displayed with a style, a new file is created and the original image is left unchanged.

Add style
STYLE NAME

i SETTINGS

OPERATIONS

thumbnail

Default

edit

medium

Default

edit

large

Default

edit

. 8 .7 . . edit
Operations

, , ,
, . ,
,
Override defaults.

11. author ,
. ,
Add style. Style name small_square
Create new style.

166

8.

,
, , .

12. ,
. ,
Scale and Smart Crop, . 8.8. Add
. width height 150,
.
, Allow upscaling.
EFFECT
There are currently no effects in this style. Add one by selecting an option beiow
Add

. 8 .8 . Scale and Smart Crop

13. , Add effect.


,
. , ,
Drupal! Image
(quicksketch).
.

(
),
. .
, - , .

14. authors image



thumbnail.
,
.

, .
1. Page settings Menu: No menu. No menu,
. Normai menu entry,
Authors Menu Main menu,
. 8.9.
2. Apply, Save. ,
,
Structure Menus (admin/structure/menu)
.

.
Add link .
Table of Contents.

167

O Page: Images: Menu Item entry


Type

Title

No m enu entry
0 Normal m enu entry

jAuthore

Menu tab

Description
1See the author* of the Oeftvttve Guide to Dmpal 7

........... _____________ j

If set to normal or tab, enter the text to use for the menu item.

Default m enu tab

If set to normal or tab, enter the text to use for the menu items description.
M enu

ff|

Insert item into an available menu.


W e ig h t

...... ~

~~

'

I . . . . .
The lower the weight the higher/further left it will appear.
Update I , Cancel
-----------* '

. 8 .9 .


,
.
. 8.1.

.
, 3.
8 .1 .
Title

(override) Title: Author biographies

Advanced settings

Machine name: biographies

Format

(override) Style: HTML List

Display name: Page: Biographies


(override) Row style: Node (teaser)
Page settings

Path: authors/biographies
Menu: Tab: Biographies (weight: 5)

Sort criteria
Filters (unchanged)

Fields: field_pagecount (desc)


Node: Type = Profile
Node: Published =Yes

,
. 8.10, , .
1. .
Page settings Path authors/pictures,
Default menu tab.
2. Authors.
.
3. Weight -5,
( ),
.
4. Update. Parent menu item
Normal menu item ( Already exists).

168

8.

5. Authors .
( ).
Authors O iZ e of Chaptere J SuggesHo

J Buying the Book 1

Home

Authors
Authors

Biographies

. 8 .1 0 . Biographies,
Authors


, ( ,
, ). .
authors, Views
. Views ,
, , .
.
authors authors/pictures. ,
, 27.

,
, ,
. .
.
, ( Attachment,
, , ).
. 8.10
.


,
.
Manage display .
.
Author
profile, . 8.11.
Structure Content types Manage display Author profile ( admin/structure/types/
manage/profile/display).

, ,
( , ,
, , ,
. .).

held

.
-

...

............... .......

169

FORMAT
.... .........

Fof
Image style

?
Unk image to

Update
4.

Biography

*f

Drupal.org user ID

tf

Croups,Drupal.org user ID

4.

Twitter

Web site

4.

DefinttiveCuWe.org account

<Hidden> $
IrSrie

Defat*

!i

Default ~T$1

{ -

Default

InSrw ' "\


Above

Cancel

Default

1 234
Display with prefix and suffix.

1 234
Display with prefix and suffix.

Jt
iM..

Tate, as fink(defauK)
Default

$t

Hidden
Approximate pages

. 8 .1 1 . Manage display
Author profile

. 8.11
Author profile (
). Headshot ,
, , .
,
Headshot. Biography ,
inline.
,
<Hidden> Hidden.
Approximate pages, ,
.
( ). . 8.11
DefinitiveGuide.org account web site,
, .

Drupal
, Save .
.
, , ,
(. drupal.
org/node/857312). , ,
Save .

, Save? Update
Drupal ,
.
. , ,
Save.

170

8.


Author profile. ,
Manage display. Teaser,

.
Custom display settings (
), . ()
Drupal Full content, Teaser, RSS, Search index,
Search result Print. Search,
Drupal.
Teaser,
; , Full
content, , .

Manage display.


, (
30), Display Suite (drupal.org/project/ds).
Node reference .
Views (row style: node),
,
.
- (Anjali Forber-Pratt) (. dgd7.org/anjali).


Teaser, ,
.
, .
1. ,
. 8.12, Structure Content types
Author profile Manage display.
Teaser (admin/structure/types/manage/profile/display/teaser).
2. Headshot Image style medium,
Link image content (
).
3. , Biography ( body),
Summary or trimmed.
600 (, , ; ,
Drupal ). ,
. ,
300 , Trimmed
Trim length.
4. ,
.

171

Summary or trimmed
, Trim length,
Trimmed . ,
. Drupal 7
. ,
. ,
, Drupal
Long text and summary, , ,
.
Default

Hide row weight*

FIELD

WEIGHT

PARENT

Headshot

fo ~ j

;~Nenr^T*

Biography

(T 1

: FORMAT

LABEL
<Hldden>

t;

image

Image styie:
medium
Linked to content

t-

Formal settings: Trimmed


Trim length *

GEZIJ
Update
Hidden
Croups.Drupal.org user

T5" 1

- 31

>'fnSne

T ti

<Httden>

Cancel

tS

. 8 .1 2 . Teaser
. headshot. Show row
weights,


, Drupal .
DefinitiveGuide.org: ,
.
, , ,
. Book
(drupal.org/handbook/modules/book). ,
: Drupal.
Modules (admin/modules), Book allows
users to create and organize related content in an outline (
). !
Drupal,
. , Book
Save configuration .

Book (admin/help/book) ,
, .
,
, , .
,
. .
, .
Book drupal.org/node/1041498.
Drupal 8, 1
, .

172

8.

Book ,
Book page. DefinitiveGuide.org
Book ,
.


,
Content Books Settings (admin/content/book/settings).

, ( Drupal 7
, ).
Structure Content Types
Book page (admin/structure/types/manage/book),
, . 8.13.

Home * Administration * Structure * Content

typts

Chapter
Nam e *
Chapter

Machine name; book (Edit}

The human-readable name of this content type. This text will be displayed as pan of the ifst on the Add new content page- it is recommended that this name begin with capita)
Setter and contain onty letters, numbers, and spaces. This name must be unique.
D e scrip tio n

A summary or a list of headings for a chapter, appendix, or other book part in The Definitive Glide to Drupal 7.

....."........" ............f ..... "

'.... '

"' J

Describe this content type. The text wilt be displayed on the Add new content page.
S u b m issio n fo rm s e ttin g s
Chapter title

T itle e ld label *
Chapter ette

P u b lish in g o p tio n s
Published , Create new revision

Preview b efo re sub m ittin g

D isp la y s e ttin g s
Dont display post information

o D isabled

C o m m en t s e ttin g s
Open, Threading , SO comments per
page

Required

O ptional

M enu s e ttin g s

E xplanation o r s u b m issio n g u id elin es

. 8 .1 3 . Book page,

Book page Chapter ( book )


.
,
.
1. Submission form settings Title field label Chapter title.
2. Publishing options , Published Create new revision
.

Create new revision .


, ,
, .

173

3. Display settings Display author and date information,


. 8.14. Drupal
.
, ,
, .
Submission form settings
Chapter title

Display author and date information.


Author username and publish date will be displayed.

Publishing options
Published, Create new revision
Display settings
Don't display post information

. 8 .1 4 . ,
( submitted by)

4. Save content type. ,


Book, DefinitiveDrupal.org.


1,
. Book
, ,
. Book,
, . 8.15.
PERMISSION

USER

J L -u

!,.USER
.i___u-JL)

ADMINISTRATOR

AUTHOR

TRUSTED

Book
Administer book outlines

Create new books

Add content and child pages to books

&

View primer-friendly books


View a book page and all of its su b -p ag es as a single
document for ease of printing. Can be performance heavy.

5?

. 8 .1 5 . Book (admin/people/permissions#module-book)

, Book,
. , (Administer book outlines),
, (Add content
and child pages to books), .
, (Create new books) .
, , (View printer-friendly
books), .
, .
Chapter, . 8.16.
Administrator.
, .
, .

174

8.

PERMISSION

USER

USER

Chapter Create new content

Chapter Edit own content

Chapter Edit any content

Chapter Delete own content

Chapter Delete any content

ADMINISTRATOR j AUTHOR I trusted|


[
: 1

. 8 .1 6 . Chapter (book) Node

, , ,
Node.
Node, , .

, Book
. Content (admin/
content), , . 8.17.

. 8 .1 7 . Books

List Settings

Configure Help
Modules .

, .
.
Settings (admin/content/book/settings), List,
, , .
Chapter Book,
Book, .


, ,
, .
(
.)
, , Chapter.
1.
Structure Content types manage
fields (adm in/structure/types/m anage/book/fields). ,
, Manage Fields.
2. (body).
edit (admin/structure/types/manage/book/fields/body).

175

3. Label Chapter summary , Required


field , , ,
. Save settings.
4. Chapter number, . 8.18. ,
Integer, ,
, . Text.

. 8 .1 8 . Chapter Chapter number


5.
, . 8.19.
M axim um length *

! ----------------------------------------->
The maximum length of the field in characters.

|
Save field settings

. 8 .1 9 . ,

6. ,
, . 8.20.
: Size o f textfield 4

~Z T 3

Text processing
Plain text

. 8 .2 0 . Chapter number

, ,
.
Help text : The chapter number (integer) or an
appendix letter ( ( ) ).

176

8.


( Manage fields)
, ( Display fields).
1. , ,
large,
. 8.21.

. 8 .2 1 . Chapter summary
default

,
. ,
, . Drupal ,

.
, . , ,
, , .
, .
(. 13 31).

2. . 4 Devel,
(Lorem ipsum),
.
Firefox (sogame.cat/dummylipsum).
.
3. Chapter,
, . Add content
Chapter (node/add/book). Chapter
title . dgd7.
Summary .

Book ,
.
.

177

4. Book outline.
Book <create a new book>, Drupal ,
This will be the top-level page in this book (
), . 8.22. ,
.
Book outline

Book

1
Revision Information

i New revision

flC W D O 0K >

; Your page will be a part of the selected book.


This w ill be the top-level page in this book

URL path settings


No alias

Weight

(o

Comment settings

Mj

Pages at a given level are orderedfirst by weight and then by title,

. 8 .2 2 .

,
. , ,
.

5. ( )
Add child , . 8.23.

.
+ Add child page Printer-friendly version

. 8 .2 3 . Add child page ( Printer-friendly version),


Book

Menu Block
Book ,
. ,
, Book,
. , Drupal .
Menu Block, ,
.

, Book . Menu
Block, . drupal.
org/project/menu_block .

, . 8.24.

Drush (drush dl menuJblock;


drush en -y menu block). Drush 2 25.

1.
(admin/structure/block). Add block link

178

8.

Add menu block (admin/structure/block/add-m enu-block).


Advanced options, ,
. 8.25.
Modules

* To use menu blocks, find the "Add menu block* link on the administer blocks page.
The configuration options have been saved.

. 8 .2 4 . , Menu block

Block title as link


Make the default block title a link to that menu item. An overridden block title will not be a link.
A d m inistrative title

This title will be used administratively to identify this block. If blank, the regular title will be used.

Menu
f Definitive Gtide to Drupal ? outfne of chapters $ !

Parent item
~ Definitive Oiide to Drupal 1

$t

The tree of links will only contain children of the selected menu item. Using <the menu selected by the
page> can be customized on the Menu block settings page.

Starting level
1st leve* {primary)

I 'i f

Blocks that start with the 1st ievei will always be visible. Blocks that start with the 2nd level or deeper
will only be visible when the trail to the active menu item is in the block's tree,
Make the starting level follow the active menu item.
If the active menu item is deeper than the level specified above, the starting level will follow the
active menu item. Otherwise, the starting level of the tree will remain fixed.
M axim um depth

From the starting level, specify the maximum depth of the menu tree.
Expand ail children of this tree.

. 8 .2 5 . ( ,
)

2. Block title as link .


,
Drupal Show block only on book pages.
.
3. , Menu Definitive
Guide to Drupal 7, .
Parent item <root of Definitive Guide to Drupal 7>,
Book ,
: Definitive Guide to Drupal 7.
4. , Block ,
.
, .

179

Region settings Left sidebar,


Visibility settings Pages Show block on specific pages
All pages except those listed <front>.


JavaScript.
, ,
( drupal.org/node/1039666).
, .


, ,
.
. Omega (drupal.org/project/omega),
,
Context (drupal.org/project/context),
, .


,
.
1. Structure Menus
Add link Main menu (admin/structure/menu/manage/main-menu/add).

Add menu
. .

2. ,
( 50).

Outline of Chapters;
node/50;

, 3, ,
.
3. ,
. Drupal
, .


,
.
, HTML-
. , Drupal
, .
Author profile
Chapter summary.
, ,

180

8.

. Author profile
. Chapter
summary (admin/structure/types/manage/book/fields),
Author profile.

.

Relation (drupal.org/project/relation) (
Awesome Relationships), ,
, Profile2 .
References , ,
Node reference User reference.

Resource
,
, .
1. Resource. Drupal
resource.
2. reference page or other resource for the Definitive Guide to
Drupal 7. Connects to a book chapter (
Drupal 7. ).
3. Publishing options Published Create new revision.
, Menu settings, ,
.
. Main menu .
4. , Submit again,
Add Another ( Drupal 6 Drupal 7 20).
5. .

Content
Overview (drupal.org/project/content_type_overview), 4.

, , ,
.

Image
, , ,
.

, ?
, -
. , ,
race course ()
() decimal,
. , , ,
, . , Suggestions,
Resources Articles definitivedrupal.org tag term.

181

Resource

, ,
, image,
.
image .


resource ,
, , . ,
.
File. Attachments file (
).
1. File (
Image, File): Allowed file extensions File
directory. sql,
. 8.26.
.sql. ,
resource.
A llow ed file e x te n s io n s *
txt, zip. tar, gz, tar.gz. sql, csv, ods, xte, odt, doc, pdfj

Separate extensions with a space or comma and do not include the leading dot.

File d irectory
resource

Optional subdirectory within the upload destination where flies will be stored Do not include preceding or trailing slashes.

. 8 .2 6 . File Allowed file extensions File directory,


2. Number of values Attachments field


Unlimited, .
Enable Display, ,
. ,
Files displayed by default.
3. . resource
.


References, Node reference User
.
1. Resource (admin/structure/types/manage/
resource/fields) Node reference, . 8.27.
,
.

reference,

Add new field


Chapter

fie ld , chapter

Label

Field name (a-z, 0 -9 , J

Node reference
Type of data to store.

$
R ^B

/ Autocomplete text field


Select list
Check boxes/radio buttons

. 8 .2 7 . Resources ,
Chapter summary

J
|

182

8.

2.
Select list .
3.

Content types that can be referenced Chapter


summary.

4. , Required field,
Save settings.

Resource
, , Manage display (admin/
structure/types/manage/resource/display) .
Default; ,
,
. body,
Table of Files , . 8.28.
FIELD

LABEL

FORMAT

4*

Body

<Hidden i

J*

Attachments

Abor/e

Chapter

I In*

$
) $1

Default
Table of files *
S {>

Hidden
No field is hidden.

. 8 .2 8 . Resource

Default


, Resource .
?
Chapter,
. ,
?
, Drupal 6
, Drupal 7. Relation
(drupal.org/project/relation). ,
Views.
, .
1 . Resources (
resources).
2.
. ,
. Create Page, Create Block (
, ) Continue & edit.

Content:
Published (yes) Content: (=Resource),
.

183

3. Title Content. Create a label;


, . Link this field to the
original piece of content ,
. Style settings Wrap field in HTML
HTML element 4.
Apply.

,
Advanced ( Views Contextual filters
Arguments).
,
.
,
. :
Chapter summary Resource.

, .
Views.
1. field_chapter (field_chapter) - nid Fields. Views
, : Appears
in: node:resource. ,
Search, ,
Ctrl+F, Appears in.
, , . ,
, ,
. .
2. block .
When the filter value is NOT in the URL Provide default value.
3. ,
, ,
Content ID from URL.

( , moresite
) Views (
node/198), 198 URL-.

,

Views , .
,
( Block).
Structure Blocks (adm in/structure/block),

Views ,
. ( )
, Advanced Help (drupal.org/project/advanced_help),
, .
Views . -,
Drupal.org ,
Drupal. . -, Drupal
IRC. , .

184

8.


, ,
. Drupal (
). ,
( Narno) ( davereid), Gravatar,
(
, , libravatar.org).
.
drupal.org/project/gravatar.
1. Configuration People Gravatar (adm in/
config/people/gravatar). ,
, ,
user.
(. 8.29).
Default image
Global default user image
There currently is not a global default user picture specified. This setting can be adjusted in the user pictures settings.
0 Module default image (white background)

. 8 .2 9 . , Gravatar
( )

2. (Gravatar size) 100


(. admin/config/media/image-styles/edit/
thumbnail), ,
(. admin/config/people/accounts).
3. Image maturity filter G
( , PG).
, ,
Gravatar
.


Drupal 7 ,
. ,
Configuration Media Image styles (admin/config/
media/image-styles).

(admin/reports/status)
GD-, Rotate Desaturate.
.
drupal.org/node/256876. , drupal.
org/node/758628, Drupal ,
Imagemagick.

, Rotate
Rotation angle, , .
,
, ,
.

185

, , Gravatar, ,
gravatar (. drupal.org/node/334630).
, , CSS3 (. 15
dgd7.org/86).
!

Filtered HTML, ,
, HTML-. -
, , .
img,
. Full HTML ,
,
. ( ,
- .)
: HTML, ,
.
.
.
Filtered HTML Full HTML (
) HTML-.
Drupal 7 .
,
Filtered HTML, .
, ,
: img, h i h2 h6, sup.
1.
Configuration Content authoring Text formats, Add text format (admin/
config/content/formats/add) Filtered HTML Plus (
filtered_html_plus).
2. Roles administrator, author trusted (,
).
3. Enabled filters ,
Filtered HTML: Limit allowed HTML tags, Convert line breaks into HTML, Convert URLs into links Correct
faulty and chopped off HTML Code filter,
. , Limit allowed HTML tags.

JavaScript
Filter processing order . JavaScript
.

4. , Filtered HTML,
Filter settings. Limit allowed HTML tags.
, Allowed HTML tags. ,
(. 8.30):
<> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl>
<dt> <dd> <img> <h2> <h3> <h4> <h5> <h6> <tt> <output> <q> <sub> <sup>

186

8.

Filter settings

U mlt allowed HTML taos

. ____
A llow ed HTM L tags

Convert UR Li Into links


Enabled

A list of HTML tags that can be used. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.

r a > <em> otroog?-

<btockouoe> ^-codo> <> < <b> <dl> < a x> <dd> <

<

>

<h5>

<tt> output

< s u ti> <tup>

} Display basic HTML help in long filter tips

. 8 .3 0 . HTML- ,

5. Save configuration, ,
, . trust.



, , , ,
, ,
. ,
,
: Insert (drupal.org/project/insert) Image resize filter (drupal.
org/project/image_resize_filter).

, , , Drush:
drush dl insert image_resize_filter; drush en -y insert image_resize_filter

,
,
.
,
. , Drush ,
.

Image resize filter


(admin/config/content/formats),
The image resize filter has been installed. Before this does anything, the image resize filter needs
to be added to one or more text formats. ( . ,
). , <img>
HTML-, .
Image Resize Filter .
Full HTML Filtered HTML Plus,
Image resize filter Enabled filters (
Save configuration).
Insert,
.
Image (
, image).
image Chapter summary (book).
Structure Content types Chapter
summary Manage fields edit Image (admin/structure/types/manage/
book/fields/field_image/edit). ,
Insert. ,
.

Status

187

Enable Alt field.


: , ,
, .

Insert Enable insert button. ,


( Maximum image insert
width) 600 ;
.
,
, Insert.
HTML-. Image resize filter
Drupal , height
width. ,
, ,
. WYSIWYG (. 4 dgd7.
org/modules),
.

Insert URL-,
,
Pathologic (drupal.org/project/pathologic).
Correct URLs with Pathologic (,
). ,
. , http://dgd7.localhost/
http://definitivedrupal.org/ . Pathologic
,
RSS- , , , Drupal
Planet (drupal.org/planet).

Status
, ,
, ?
Status Suggestion
. ,
Field Permissions, (drupal.org/project/
field_permissions).

1. Field Permissions

Configure. Permissions
, .
, - . ,
Structure Field permissions (admin/structure/field_permissions).
2. ,
. field_status (
) Suggestion Used in.
3. Status Suggestion.
. Field Permissions
,

188

8.

: Structure Content types Suggestion Manage fields Status (admin/


structure/types/manage/suggestion/fields/field_status/fieldsettings).
4. . 8.31 There is data for this
field in the database. The field settings can no longer be changed (
. ).
Drupal ,
( , ).
FIELD SETTINGS

There is data for this field in the database. The field settings can no longer be
changed.

These settings apply to the Status field everywhere it is used. These settings impact the way
that data is stored in the database and cannot be changed once data has been created.
Field perm issions

Create fieldjstatus (edit on content creation}.


Edit fieldjstatus, regardless of content author.
Q Edit own field_status on content created by the user,
fji View fieldjstatus, regardless of content author.
Q View own field_status on content created by the user.
Use these options to enable role based permissions for this field. When permissions are enabled,
access to this field is denied by default and explicit permissions should be granted to the proper user
roles from the permissions administration page. On the other hand, when these options are disabled,
field permissions are inherited from the content view and/or edit permissions. In example, users
allowed to view a particular node will also be able to view this field, and so on.
Vocabulary *

The vocabulary which supplies the options for this field.

Save field settings

. 8 .3 1 . Field permissions

,
.
:
Permissions. ,
, , , .
.
Drupal 7.

5. : Create field_status (edit on content creation), Edit field_status, regardless


of content author View field_status, regardless of content author. ,
, ,
Field permissions.
, . 8.32.

Create edit, Field permissions


-. ,
Suggestion.

URL- Pathauto

PERMISSION

ANONYMOUS

AUTHENTICATED

USER

USER

ADMINISTRATOR

AUTHOR

ef

189

Field Permissions

Administer field permissions


Manage field permissions and
fieid permissions settings.

Create field_status
Create fteid_status (edit on
content creation).

Edit any field^status


Edit fie!d_status, regardless of
content author.

View any fieidstatus


View fieidjstatus. regardless of
content author.

. 8 .3 2 . .
, ,

6. Field permissions: When permissions


are enabled, access to this field is denied by default and explicit permissions should be
granted to the proper user roles from the permissions administration page (
,

.)
People Permissions (admin/people/permissions).

7. administrator author.
Status. Save
permissions.


, , hook_form_alter(). Field
permissions . , , ,
,
. , Suggestion status,
, .

URL- Pathauto
URL- ,
. , , .
Pathauto (drupal.org/project/pathauto) Token (drupal.org/project/token).
drush d l pathauto; drush en -y pathauto
Project pathauto ( 7 .x - 1 .0 - b e t a l) downloaded to
/h o m e /b en /co d e /d g d 7 /d ru p al/sites/a ll/m o d u le s/p ath au to .
The fo llo w in g extensions w i l l be enabled: pathauto
Do you r e a lly want to continue? ( y /n ) :
pathauto was enabled s u cc es sfu lly , [ok]

[success]

Token, Pathauto,
: drush dl pathauto token; drush en -y pathauto.

190

8.

Pathauto Configuration.
Configuration Search and metadata URL aliases.
, Pathauto.
, Patterns (admin/config/search/path/patterns).
Default path pattern.
content/[node:title], content
.
, [node:content-type:machine-name], :
[node:content-type:machine-name]/[node:title]

, ,
.

Basic page ,
title, [ node:title ]. , , About page, ,
page/about.
.

Suggestion .

. Token,
drupal.org/node/691078.

! .
,
,
. ,
Drupal, . ,
, ,
! 30.
DefinitiveDrupal.org
.
Views

dgd7.org/moresite.

III.
9
Drupal-.
10 ,
.
11 ,
,
, .
12
.
13 ,
.
14 ,

.

9. Drupal-

Drupal ,
.
, Drupal

, Drupal
, , , .
Drupal- . ?
? ?
Drupal- , Drupal,
, , , ,
. : IRC- ,

Drupal . Drupal.org,
, .
Drupal.
org. ,
.
Drupal , , .
Drupal 7 . Drupal 5
2007 .
. ,
, .
- , Drupal, .
, -
. , , ,
, ,
, /
, Drupal .
, ,
. ,
,
? ,
. ,
Drupal. , ,
, ,
.
Drupal ,
. , Drupal,
. . ,
;
, ,
. ,
, .
, Drupal- ,
, .

193


Drupal ,
IRC (Internet Relay Chat -). #drupal
, #drupal-contribute
, , Drupal.org . .
,
IRC- .

, ,
.
, .


Drupal- .
(, Drupal.org) ,
.
, .
drupal.org/language-specific-communities.

,
Drupal- - .
, Drupal.
(
, ),
,
.
Drupal Planet
Drupal Planet (drupal.org/planet) Drupal
, .
, ,
, , ,
, Drupal . ,
,
.

( , )
,
. , ,
, , . ,
- ,
, Drupal ,
.
.
Lullabot (lullabot.com/podcast) ,
2006 . ,

194

9. Drupal-

, Drupal
. lullabot.com/podcast,
Drupal Voices (Kent Bye)
Drupal-, .
DrupalEasy (drupaleasy.com/podcast)
, Drupal-,
.
Acquia (acqula.com /podcasts)
Drupal. Drupal
. ,
Drupal.
Geeks&God (geeksandgod.com /podcast) ,
. Drupal.
, Drupal-
.
,
.
Drupal dgd7.org/podcasts.
Drupal.org
, , drupal.org/forum,
. ,
. ,
, , .
Groups.Drupal.org
Groups.Drupal.org ( g .d .o )
,
, .
,
Drupal ,
. ,
.

, , Drupal- ,
.
drupal.org/mailing-lists. :
( , !),
.
.
, .

Drupal,
, ,
Drupal Camp (meetups).
Drupal.org.
.

195

Drupal Camp
, Drupal Camp, , ,
. .
.
Drupal-,
. ,
, . Drupal Camp

Drupal;
.
DrupalCon
DrupalCon Drupal .
, .
. . 2007 DrupalCon (,
) 300 , 2010 -
3000 . 2011 ,
DrupalCon . ,
Drupal, ,
.
, , DrupalCon
. , BoF-
( Birds of a Feather )
. ,
Chx Coder Lounge
. ,
Drupal, / , .
Drupal Meetups
Drupal
Drupal
, ,
Drupal.
groups.drupal.org/events.
,
, ,
.
Drupal.

. .
, ,
, . , ,
, Drupal. ,
(
) . , ,
Cristefano , ,
, .

, , g.d.o,
Drupal Meetup.
com. , , Drupal

196

9. Drupal-

(meetup.com/drupalwor1dwide).
Meetup.com, Facebook
groups.drupal.org.

IRC
Drupal-
IRC (Internet Relay Chat).
drupal.org/irc. irc.freenode.
net:, #drupal-support,
#drupal, #drupalcontribute.
,
.
, , IRC
. , :
. , #drupal-contribute
, #drupal-support .
drupal.org/irc.
; .
,
. , :
?. , ,

, .
. (
) ,
; .

. ,
, .
( ) ,
. pastebin (, drupalbin.
com) .
, . , -
, ,
, IRC, , ,
.
, .
, , .
. ,
, ,
.
, ,
, ,
.
. , Drupal,
, .
.

.

197

.
. ,
.
, IRC , .
, .
IRC-
Drupal, ,
Drupal.
. ,
-
Drupal. - .

. (Amitai Burstein)
Organic Groups Drupal 7,
. (
) .
, : ,
. ,
,
, , .


, , Drupal, .
,
. Drupal,
Drupal.org.
, , drupal.org/project/issues/drupal,
, , drupal.org/
project/issues/HMR_npoeKTa, _ .
, Drupal.org.
Drupal
; .
Drupal , .
- ,
. . -
, .
Drupal.org Block
Configuration Contributor Links,
Drupal , ,
.
, :
, . -
( ,

. .), .
, Drupal,
, .
(webchick.net/6-pass-patch-reviews).

198

9. Drupal-

, ,
, . ,
-
, ,
.
,
Drupal , .
( )
.
, ( Drupal, ,
, ).
,
.

( ,
).
,
.
, . ,
, .

Drupal- , ,
( ), , ,
, , , ,
, ,
. ( ,
Noneck, ,
Drupal , .)

(, Noneck ,
). ,
Drupal, , ,
Drupal
. ( Drupal ,
-.) , , Drupal-
Drupal,
Drupal-. ,
Drupal. ,
, , ,
.
?
Drupal.
. , , ,
Drupal.
, .
, ,

199

. .
. :
Drupal.org .
.
, Drupal.
Drupal .
- Drupal
, Drupal.
.
, API Drupal 8
, Drupal.

Drupal.
Drupal- ,
.
. , . 31
Drupal ( , ).
Drupal-.
- .
,
,
. !

Drupal- *.drupal.org.
, -
: dgd7.org/participate.

10.

! Drupal
. Drupal
.
: ,
,
.
.
, , .
Drupal ,
,
. - , , .
.
, , ,
,
. ,
, ,
, .
Drupal, , ,
.
, ,
. , , .
, ,
.


, , , .

. ,
,
, . ,
, - .
, . ,
, ,
, .
,
, .
, ,
,
, .
60 ,
4 . ,
, (Google Apps) SMTP- ,
DNS- , Drupal , ,

201

.1-
, ,
, .

.


, , ,
.
:
1. , . (
- Drupal
.)2
2. , .
. (, , 4 .)
3. , Dreamweaver/
Publisher, .
, .
4. ,
, 2001 .
5. ,
.
6. ,
.
7. . ,
, ,
.
8. ,
, ,
, .
9. , Drupal.
.
.
,
, , ,
. , -
.
10. , , ,
, .
;
. ,
, 6 .
1 ( , ).
, , - ,
4 , .
2 Drupal (. Buzzr http://
buzzr.com Drupal Gardens http://drupal.gardens.com),
.

202

10.

,
. ,
11 , .
, 3 10.
, , ,
. ?
? , ,
?
?. .
. 10.1, .


( +
)

. 1 0 .1 .

. , ,
, .
;
,
. , .
Drupal
. ,
. ,
. 10.1.

1.
' : ?
? ? ?
? ,
. ,
.

2.
.
, . ,
GoMockingbird (http://gomockingbird.com), . 10.2.
, .
, .

203

(login) (signup),
.
Facebook .
. .
,
.
Login I Signup

(. Search

Lorem ipsum dolor sit amet, maiores ornare ac fermentum, imperdiet ut vivamus a, nam lectus at
nunc. Cum quam wuismod sem, semper ut potent! pellentesque quisque. In eget sapien sed, sit
duis vestlbulum ultrlcles, placerat morbl amet vel, nullam In In lorem vel. In molestle allt dui dictum,
praesent nascetur pilvlnar sed, in dolor pede in aliquam, risus nec error quis pharetra. Eros
metus quam augue suspendisse, metus rutrum risus erat in. In ultrlces quo ut lectus, etlam
vestibulum urna a est, pretium luctus euismod nisi, pellentesque turpis hac ridiculus massa.
Venenatls a tacitl dolor platea, curabltur lorem platea urna odio,convallis sit pellentesque lacus
proin. Et Ipsum velit diam nulla, fringilla vel tincidunt vitae, elit turpis tellus vivamus, dictum
adlpiscing convaliis magna id. Biverra eu amet sit, dignisslm tincidunt volutpat nulla tincidunt,
feugiat est erat dui tempor, fusee tortor auctor vestibulum. Venenatis praesent risus orci, ante nam
voiutoat erat. Cursus non mollis interdum maecenas, conseauat imperdiet oanatibus enim.

. 1 0 .2 .

) ED IE

XX
XX
XX

,
.
?,
?. ,
, .

3.
, , , ,
. ,
.
-, , Photoshop.
,
. . , ,
, .

4.
?,
?.
. ,
.
, ,
, . -, , .

204

10.

5.
: , , .
.
, , ,
. ,
.

6. /
. . ,
: , ,
.
. .
, . ?
, URL-
/nod/? ?
? 16/
IE 7/IE8, Firefox, Safari? , ,
, .
?
. , ?
.
,
.

7.
, , : ,
Drupal,
Drupal.
, , ,
.


, ,
, . . Drupal :
(waterfall) (agile).
.
, ,
, .
.

.
. , ,
.
,
.

205

.
.
, . ,
, , , ,
, .
, .
,
.
,
.
,
. . 10.1
, .
1 0 .1 . Drupal-npoeicra

(

)

, ,
.
, .
,
. , ,
.
- ,
, .
.
,
, , ,
.
( - )>
. , ,
.

206

10.


, ,, , , .
:
?
?
?
?
?
?
. -
.


,
. , ,
( , ) .
, .
,
. ,
, , , , .
:
, , .
,
. ,
: ,
, . ,
, :

. , .
: ,
.
, . .
(, .)
,
, . :
X ? ,
?.
BeachHouse
:
BeachHouse ,
.
:
, .
.
.
.

207

.
.
.
:
1: , , 18 25 .
, .
.
.
:
.
2: , 28 3 .
: .
.
.
-.
.
.
3: -, 5 9 .
: .
, .
.
.
.
: .
4: , 12 16 .
: .
.
, .
.
: .
5: , 19 23 .
: .
.
.
: .
6: - , 25 30 .
.
.
, 29 .
7: , 1 7 .
.
.
.


, , . ;
. ,

208

10.

.
,
.
.
?
, ? ?
30 % .
,
?
? .
, .
.

.
, ,
, ,
, !
, ,
. ,
,
. , ,
.

.

, . ,
.
, .

.
, ,
. ,
.
, ,
, , ,
, .

/
, .
, ,
.
,
Coming Soon Under Construction1.
,
1 . ,
. , , !

209

. .
,
, ,
.
. , , ,
.


, ,
. .
,
. , .
SMS.
:
Unfuddle;
Basecamp;
ManyMoon;
5pm;
Liquid Planner;
Teambox.
, Drupal.
.
, . ,
, .
, , .
. ,
: .
, , , .
. ,
,
.
, .
, , , ,
. , ,
Drupal .
.
,
.


.
,
. .


,
. ,

210

10.

.
, ,
. , , - ,
. ,
Drupal :
(wireframe) ,
, . , .
(mockup) , Photoshop
, .
.
(layout) ( )
.
(concept design) .
(theme) , .
.
(module) , Drupal.
.
(features) Drupal,
. , features
() .
, , ,
, .
- . ,
, . ,
:
?
?
?
?
?
: ?
,
, .


.
; , .
, ,
.
:
?
?
?
?
?
.
Drupal Facebook. ,

211

,
.

/
.
, , .
, , .
.
(30 ) , .
:
, ?
?
?
?
,
, .
.
.


,
. , ,
.
20 .
,
.
.
:
?
?
?


,
. ,
.
:
?
?
?
?


,
, .
- , .
.

212

10.

, :
.
.

? .
,
. , ,
,
.


,
. ,
. ,
. - ,
.

. , , ,
.
:
?
?
?
.


! , ,
, , ,
. //
, .


.
,
.


, , ,
(user stories).
? ?
, .
, .
.
:
[-] [ *], [].
: ,
.

213

[] [], []. :
,
.

. ,
.
, .
. ,
.



. , ,
.
(new), ,
- , (assigned).
,
, (accept).
(rejected),
;
.
, (resolved)
, ,
.
,
(closed). , ,
(reopen).
.
,
. ,
.
,
.
. ,
Photoshop BeachHouse HTML/CSS-
. , ,
.
, .

,

.
.
, ,
.
. :
?
?

214

10.

?
,
?
,
.
,
. , ,
,
.
, .
;
.

.
, -
.

,
. :
.
.
, .
.
.
.
.
,
.
! ... . ,
, , .
, . :
.
.
X Y.
.
. .
. . . ,
. .
.
, , ,
, , ,
.
, ,
.
.

215

,
. , , ,
.
!


, (http://managinghumans.com).
, (www.scottberkun.com/books/making-thingshappen/).
Drupal-, (affinitybridge.
com/blog/managingbudgets-and-billing-while-practicing-agile-development).


dgd7.org/manage.

11.



,
,
, .
,
, .

, .
, Drupal-
, .

?
, ,
. , :
.
,
, (,
).
, ,
, .
, ,
.
.
,
, , .
,
; ,
, .

(Claudina Sarahe)
.
.
dgd7.org/document.


Drupal,
.
:
.

217

Drupal.
,
.
.
( )
.

.
, .
.
,
, (, staging.newsite.com)
URL-.
, , .
. 13.
,
, ,
. ,
? , ,
- , . ,
, .

PDF ( Wiki
). ,
.



, . ,
:
URL-
, .

.
.

, ,
.

.
/
.
/ .
/.
,

/. ,

218

11.

; ,
Drupal, ,
-. ,
, ,
, . ,
:
, .
, ,
.
, .

. (, ,
, , Microsoft Word)
, ,
, .
, , .
,
( ,
) HTML
.
, . ,
WYSIWYG (drupal.org/project/wysiwyg) .
4.


:
, ,
. , HTML.
.
; ,
.

, Microsoft Word OpenOffice.
.
PDF,
.
,
, . ,
,
,
, . ,
1 8:

This documentation will help you update content and work with the backend of your new Drupal site.
Logging into the Backend
On the left side of page, youll see a user login" box. Your username is editor, and your password it
site_admin.

User login
Username*

Password*

Create n ew account
R equest new password

Using the Admin Menu and Dashboard


The admin menu at the top gives you access to control the sites content. Clicking on the Dashboard link will
show you a list of recent content, recent comments, and newly registered users.

About Content Types


The sites content is based on the following content types:
Chapter: These are sample chapters of the book. They can only be posted by site authors
and do not allow comments.
Suggestions: These are suggestions, tips, and anecdotes for consideration in the next version
of the book. These can be created by any registered user and must be approved by a
moderator before they can be viewed on the site.

219

220

11.

Create Content: Chapter


create a sample chapter, Click Add content from the shortcut menu, and Chapter from the content listing.

Chapter pages are set up with the following fields:


Title the title of the chapter
Authorthe author of the chapter
Bodythe text of the chapter
To add the content, simply fill out all the fields, press Save, and the chapter will be published!
For deeper, more complex sites, youd include more information on specific fields, whether theyre required,
taxonomy menus, etc. One particularly nice feature in Drupal 7 is the ability to customize the Dashboard
and shortcut list (the gray bar underneath the admin menu) for each role. This makes the site editors work
easier and your documentation easier to write.



Drupal,
. . ,
, . ,
, ?
, Wiki (
MediaWiki ( www.mediawiki.org/wiki/MediaWiki) Drupal!)
(, Drupal ,
openatrium.com) Dropbox .
, ,
, . ,
, .
.
,
;
,
, .
, . Drupal
, .
, - ,
, .
:
, , .
(
).

221

,
( ).
( ) ,
.
, ,
( 15 16).
.
,
. ,
,
: ,
.


,
( ). ,
,
, , Drupal
.
.
-; , Lullabots (lullabot.com)
, ,
Drupal. (Bob Christenson) MustardSeed
Media (mustardseedmedia.com/podcast)
. , Drupaltherapy (www.
drupaltherapy.com/screencasts),
. , ,
Drupal,
.
Drupal - ,
. ,
, ,
Drupal.org . ,
.


. ,
, Drupal.
, ,
.
,
. ,
.
. , .

dgd7.org/document
dgd7.org , dgd7.org/anjali.

12.

.
, ,
. ,
:
, , , .
.
, .
,
. ,
.
.
,
, ,
, .
, , .
. , :
Quickstart ,
. , ,
. (
, ,
.)

. ( .)
,
. ( ,
.)
,
Drupal. (
, .)

.
: Linux-
Windows .
dgd7.org/devenv.

Quickstart
Quickstart (drupal.org/project/quickstart)
Windows,
LAMP.
, ,
. Drubuntu ( Drush,

Ubuntu), Quickstart Drupal (drupal.

Quickstart

223

(drupal.org/project/issues/quickstart)
(groups.drupal.org/quickstart-drupal-development-environment). ,
,
,
. Quickstart Virtual Box
Ubuntu .
, Quickstart ,
.
Virtual Box 1024 , Quickstart
18 ,
, .
,
, . , Quickstart
Windows Pro
Intel Core Duo 2 .
(
): MacBook Pro \1 (
Snow Leopard, 8 , )
, . ,
, .
,
( , Quickstart
, drupal.org/node/819720).
,
,
, .
' .
Drupal.org (drupal.org/project/quickstart).
, , (
VirtualBox;
).
1. Quickstart 0.9.1 bittorrent.
? uTorrent ( Win ) www.utorrent.com.
2. Virtualbox ( 4.0.4+).
3. Quickstart:
1) Virtualbox;
2) File Import Appliance Choose file
ova;
3) , 50 % (
1024 , 2048 );
4) Import .
4. .
5. : '.:
1) Unix: quickstart :quickstart;
2) MySQL: root: quickstart;
3) Drupal: admin:admin.
6. : drush, drush make, drush
Quickstart . . drush, :
org/node/788080),

224

12.

1) cd ^/quickstart;
2) git pull;
3) bash -x update.sh;

Quickstart , (. 12.1),
,
.
Firefox.
|*$ Applications Places System W

n v 456 8/S

, 4 1 0 8 /s

- c, phpinfo() - MoziUa Firefox


I Fite Edit View History Bookmarks

v Cf
#

, ^

Tools

Help

i http://localho$t/

! If* j Googie

% *r & Exampte.dev ^phpMyAdmin ** Quickstart Docs

I 0 Disable X C ookies1*- / CSS Sgform s^


I (j phpinfo()

Quickstart Project ff! Quickstart Croup

ESifnages * information *

Miscellaneous ^ O u tlin e*

Resize *

, ^& -drupatqmckstar. * ^

Drupal Quickstart Development Environment:


Dev Toois on th is V irtual M achine:

Q u ic k sta rt S u p p o rt a n d Q u e stio n s:

phpmyadmin

Tutorials: Youtube vjgSS

Webcmnd profiler
XHProf Viewer

Questions: Quickstart Group


Patches and bug reports: issue Queue

E x a m p le S ite s in t h i s V irtu al M achine:

Q u ic k sta rt D o c u m e n ta tio n :

examote.dev - Drupal 7
examples.dev - Drupa! 6
{user admin, password admin)

Quickstart Project
Handbook Documentation

D ru p a l S ite B uilding D o c u m e n ta tio n :

D ru p al D e v e lo p e r D o c u m e n ta tio n :

Module Usage Statistics


DrupaiModules.com

Drupai API documentation


Drush command line reference
prush Make reference
Drupai Patch Queue and Patch reviewing tips
XHProf Documentation

. 1 2 .1 . readme ,

. ,
, . ,
,
IDE Drupal
Windows .


, ,
. ,
.
,
, , .
:
.
.
HTML, CSS JavaScript.
.
-.

225


, ,
. , Git ,

, .
, ,
. , .
, LAMP
Windows
. , .
Windows WebMatrix
Microsoft (microsoft.com/web/drupal), Drupal
IIS.



, .
, .
, ,
.
Linux ,
. Applications Utilities Terminal; Ubuntu
Applications Accessories Terminal.
Windows -. Linux
( Quickstart)
, , Cygwin (cygwin.com/).
Cygwin :
1. cygwin.com/setup.exe.
2. setup.exe,
, .
3.
( ,
, ):
1) Shells rxvt, VT102, X, Windows;
2) Net openssh, ;
3) Archive unzip, ZIP-;
4) Editors nano: pico (
vim);
5) Web wget:
HTTP FTP.

,
Windows , , :
$ cd Documents\ and\ Settings

Terminal.

226

12.

Cygwin, . help
. , ,
.

HTML, CSS JavaScript



Firebug ( http://getfirebug.com/). CSS HTML
.
Firefox.
, Developer
Tools Safari ( Develop Menu,
Safari Preferences Advanced).

Firebug , admin/config/development/performance
Aggregate and compress CSS files Aggregate JavaScript files,
CSS- JavaScript-.
Configuration Development Performance.

Firebug Firefox ( Firefox


getfirebug.com Install Firebug),
Tools Firebug Open Firebug. HTML-
, .
: (

CSS-). , HTML-
Inspec ( Firebug
).
-.
, , HTML-
HTML-.
Style, HTML.
. Firebug .
(
, ,
).
, - CSS-
. ,
,
; HTML, CSS JavaScript
15 16.
;
.
Drupal for Firebug, Firebug
Drupal SQL- (drupal.org/project/drupalforfirebug).



, .

227

, -
Internet Explorer Firefox. , -
IE (
IE6, , IE9,
15% ). , ,
- .
, , ,
.
, .
. ,
, , : en.wikipedia.org/wiki/Usage_share_of_
web_browsers.
. , ,
, . , Drupal
Browscap, (drupal.org/project/browscap).
,
.
,
. ,
,

.
,
.

, .
,
:
IE Collection Utilu Microsoft
Internet ;
utilu.com/IECollection.
Mozilla Firefox releases.mozilla.org/pub/mozilla.
org/fi refox.
Multi-Safari Safari Apple,
Web Kit (
michelf.com/multi-safari). -,
Apple , .
Opera opera.com/docs/history.
Google Chrome .
,
,
, . ,
, , ,
.

-
Eclipse Netbeans (Integrated Development
Environments, IDE) , Drupal.

228

12.

,
. Eclipse PDT ( Development
Tools) eclipse.org/pdt; Netbeans netbeans.
org. Eclipse PDT:
1. Eclipse. Workbench
.
2. Drupal. Window
Preferences General Content Types.
, : .engine,
.install, .inc, .module, .profile, .theme, .test.

3. General Workspace,
Text file encoding Other
UTF-8. New text file line delimiter
Other Unix.
4. , .
General Editors, Text editors
Displayed tab width 2, Insert spaces for tabs.


,
, .
, Drupal .
, Drupal (. 31),
, .
, ,
Drupal. ,
.
.
, ,
, .
.
-.
( Drupal
100 ,
, - , ).
- ( Firefox).
( ,
).
gzip/zip.
:
( ).
, ( ;
Linux,
Apache,
MariaDB/MySQL).
drupal.org/requirements.

229

. (Drupal 7
,
FTP.
, FTP-.)
.
Drupal ,
, . ,
,
( ,
).
, ,
. ,
Drupal.
, ,
.
FTP- ,
, . ,
. ,
.
.

.
.
drupal.org/requirements.



. drupal.org/hosting , ,
Drupal. ,
, ,
. .

.
, ,
, ,
. ,
:
Drupal as a Service ( Drupal SaaS)
; ,
.
,
(
), ,
(shared hosting).
, ,

(Virtual Private Server, VPS).

230

12.

, ,
(Content Distribution Network, CDN).
, ,
,
(cloud-based hosting).
, ,
.
, .
, . (
,
.) :
.

.

.
, .
.
.

. .
,
. 10 (
).
ICANN , -.
icann.org/en/registrars/accredited-list.html.
, , .
.
.
,
URL-: ,
(Domain Name System, DNS).
FTP-
FTP-
. URL-,
, ,
FTP-.
Cyberduck FTP-,
, Windows (cyberduck.ch). Firefox
FireFTP (fireftp.mozdev.org). FTP-
,
.
.
1.
Cyberduck Bookmark New Bookmark.
FireFTP Create an account ,
. 12.2.

fjE re a ^ ^

Connect

>/

"

Edit

231

Abor

Name

** Q Applications

i J Applications

* t j dev

0 < i v

Sue

. 1 2 .2 . FTP
FireFTP Create an account

,
, .
, .
,
, (live), (staged) (development).
2.
Cyberduck
New Bookmark, . 12.3.

FTP (File Transfer Protocol)

-SSL (Explicit AUTH TLS)


SFTP (SSH File Transfer Protocol)
WebDAV (W eb-based Distributed Authoring and Versioning)
WebDAV (HTTP/SSL)
5 MobileMe iDisk (WebDAV)
S3 (Amazon Simple Storage Service)
I I Coogle Storage

Eucalyptus Walrus S3

Q Rackspace Cloud Files


Swift (OpenStack Object Storage)

|
|

Coogle Docs
Windows Azure Cloud Storage_____________________________

. 1 2 .3 . Cyberduck

FireFTP Connection .
SSH,
SFTP, SSH.
FTP-SSL ,
FTP. , ,
.

.
FTP ;
, ,
, .

3.
,
, .
-. server address, host address URL.
SSH
SCP.

232

12.

: , ,
URL-, ,
, .
,
. , Anonymous Login .
, Cyberduck
, .
.
.
4.
. .
public_HTML www (
, ).
. Cyberduck, FireFTP
,
. Drupal 1
( ).
, ,
. ,
(,
Caps Lock ).
.
FTP-.
, .
5.
(IDE)
,
.
, .
Windows Notepad++ (sourceforge.
net/projects/notepadplus); , Windows Notepad,
. Notepad,
UTF-8 (
Save).
TextWrangler (,
);
TextEdit,
.
Linux gEdit.
Microsoft Word, WordPad OpenDoc.
.
(
). , ,
, .
6.
Notepad++, ,
Preferences. Text Wrangler
gEdit , -.

233

Notepad* + Settings Preferences


New Document/Default Directory. New Document Format
Unix, Encoding UTF-8.
, TextWrangler, gEdit Notepad++
Tab ,
,
. ,
,
CSS-.
7. FTP-

( ,
). FTP-, Cyberduck FireFTP,
( ) .
Cyberduck Edit Preferences, Editor
, .
, Add program.
FireFTP
Open With Add Programs.
Add Extensions , .txt. ,
Add Programs. Browse
(, Notepad++) Apply.



. Windows (,
Cygwin), unzip.
Terminal :
$ unzip _
, Drupal.org
- , . 12.4.
, .
. , ,
.
7zip (sourceforge.net/projects/sevenzip/).

acquiadru pa l-.6O.tar.g2

atrium - 1 - 0 betalO .tgz

dvlc-1 - 0alpha3.tar.gz

drupaLcommons.-l.S.tar.gz

. 1 2 .4 . ,

234

12.


, , ,
Drupal.
1.
,
.
, .
, .

drupal.org/documentation/
install/createdatabase.

phpMyAdmin
*
.
phpMyAdmin
-
, :
1. phpMyAdmin, Privileges Add
a New User.

2. , , (
,
).
3. Host Local (
Generate, ). -
Drupal.
4. Database for user Create database with same name and
grant all privileges Go .
5.
Operations.
6. Collation utf8_general_ci
Go.

7. Drupal
, 1.


,
phpMyAdmin. ,

.

Drupal
.
, , , . ,
, .

235

Fantastico SimpleScripts.
.
.
.

. , .

.
:
1. Drupal,
,
(, fantastico-drupal7).
2.
. , (
, 1),
.
3. , , FTP Drupal (,
public_HTML), 1.
4. , (
fantastico-drupal7). sites/default/settings.php.
, , , ,
. 12.5.
---- --------------------* #endcode

*/

^databases array

'default' *>
a rra y

default *>
array (

"driver* *> mysql,


databasef > datahasenm e *,
username' *> username*,
*p a s sm r d * *> ?password *,
host > localhost',
port* *> ?f

),
);

),
_______

. 1 2 .5 . settings.php ,

Drupal

5. phpMyAdmin
, settings.php.
6. Check All, ,
With selected Drop.
.
7. Operations, Collation
utf8_general_ci Go.
8. Drupal, 1,
, settings.php.

236

12.


.
,
. ,
, .
, ,
,
.
, -.
www.dgd7.com.

13.


Drupal ,
, . , -
, . ,
, .
, ,
,
.


, .

. ,
. , .
Drupal- ,

.

.
1. .
2. ,
.
3. .
4. settings.php ,
.
5. , .
,
SFTP-.
2- 4-
, rake ant.

,
SSH. dgd7.org/deploy.

, Linux,
Mac OS X Cygwin. ,
.
Debian Ubuntu;
wiki.debian.org/LaMp.
, ,
.

238

13.

,
. ( , , data.
agaric.com/deploying-the-agaric-way.) Aegir,
Drush, Drupal
Drupal. Aegir
.
aegirproject.org.

, Drush,
25.

1.
.

.

.
.
, (
2, ).


mysqldump. , .
Drush- drush sql-dump

.
#
cd ~/code/dgd7
# ("db"):
mkdir db
# , dgd7 -
mysqldump -udgd7 -pdgd7 dgd7 > db/development.sql

mysqldump:
-u ( dgd7);
- ( dgd7);
dgd7 .
settings.php .

mysqldump, UNIX-
(Linux, Mac OS X, Cygwin) man mysqldump. man
manual ().
.

2.
: ,

. (scp).
scp - ~/code/dgd7 username@host.example.com:/var/www/

239

.htaccess; , ,
.


,
.
scp dgd7 /var/www. ,
,
. , , Apache
www-data.
ssh username@host.example.com
cd /var/www/dgd7
chown -R www-data:www-data web/sites/default/files
chown -R www-data:www-data private_files

,
, (
).

3.

.

,
dgd7.
ssh username@host.example.com
mysqladmin -u root -p create dgd7
mysql -u root -p -e "GRANT ALL ON Vdgd7\'.* TO ,dgd7,@*localhost* IDENTIFIED BY
1S3cUr3p4s5w0rD"


MySQL. ,
.
S3cUr3p4s5w0rD,
.
,
, /var/www/dgd7. ,
db.
mysql -h localhost -u dgd7 -pS3cUr3p4s5w0rD dgd7 < db/development.sql

mysql, ,
mysqldump : -h,
, . ,
, localhost.

.

240

13.

4. settings.php
Drupal . ,
, . .
settings.php
Drupal (, settings,
php), , :
http ://example.com/install. php
,
vim;
( 181) :
vi sites/default/settings.php
:181
i

( {databases = ())
:
$databases['default']['default'] = array(
'driver' => 'mysql'j
'database' => 'dgd7',
'username' => 'dgd7',
'password' => 'S3cUr3p4s5w0rD',
'host' => 'localhost',
'prefix' => '

);

, (
default)! $databases = array(),
Drupal; Sdatabasesfdefault'lfdefault'] = array( ... );
default , , , ,
, .

,
. ,
,
-, .
, ,
php (, Apache mod fcgid mod_php).

5.
, , ,
, . ,
- ( Apache) ,
Drupal, . ,
:
.
( icann.org/en/registrars/accredited-list.html).
-, (DNS) ,
.
, DNS-.

241

, , IP-
.

,
. (
) .


- ,
, . /var/www/dgd7/web.
( Drupal web, dgd7.)

, Drupal,
-. Apache, ,
,
. !

- Apache; Drupal,
.
Apache .
/etc/apache2/sitesavailable ( Debian).
Vim vi /etc/apache2/sites-available/dgd7 (
dgd7 ). , ,
13.1.
1 3 .1 . Apache definitivedrupal.org

<VirtualHost *:80>
ServerAdmin webmaster@agaricdesign.com
ServerName definitivedrupal.org
ServerAlias www.definitivedrupal.org dgd7.org www.dgd7.org
definitivedrupal.mayfirst.org
DocumentRoot /var/www/dgd7/web
<Directory />
Options FollowSymlinks
AllowOverride None
</Directory>
<Directory /var/www/dgd7/web>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>


sudo a2ensite dgd7 ( dgd7 ,
Apache ). , Apache
.
Apache,
( ):
sudo /usr/sbin/apache2ctl -t
sudo /etc/init.d/apache2 reload

242

13.

,
!
Apache apache.org/docs/current/vhosts.
AllowOverride
.htaccess Apache,
Drupal.

, ,
Apache Vhost, definitivedrupal.mayfirst.org,
. ,
. ,
.

, ! ,
,
.

( Lullabot)
,
,
. , .
,
Backup and Migrate (drupal.org/project/backup_migrate), 2.
,
/ .

.
, ,
.

, ,
. ,
,
, . ,
.

-. 2 ,
14,
, : ,
.
, ,
, , . ; ,
. ,
.

243

. ,
. ,
. ,
.

Drush Git Backup.


Drush- ,
.
Git. git
diff. Drush, ,
. DGB
github.com/scor/dgb.


drupal.org/node/22281.

Backupninja.

Backupninja
Backupninja /etc/backup.d
. ,
, MySQL.
, Debian,
apt-get install backupninja.

Linux, Debian,
backupninja https://labs.riseup.net/
code/projects/show/backupninja.

man backupninja ; ,
ninjahelper. ,
:
new ;
quit ninjahelper.
, ,
:
sys;
mysql;

rd iff ( , ).

SSH. ninjahelper
ssh-,
.


, ,
. ( backupninja,
/etc/backup.d).

244

13.

, . ,
.
, .
, ,
.

,
. , , , ,
( ).
,
. ,
MS Word OpenOffice.org.
. , ,
Firefox Chrome.

. ,
.
, . ,
,
Drupal.



, , .
, , ,
.

, 6,

update,
php . .

. .
. ,
.
,
, (,
) ( ).
.

, Drupal, Deploy (drupal.org/project/


deploy) , .
, Drupal 8 .
Deploy . ,
. ,
, .

245

Drupal;
( ).

, .
. ,
,
.

.
. .
, ,
Drupal .
. , , Drupal-
.


:
1. .
2. ,
(, . .). , ,
.
3. .
, , update.php.
4. .

, , Environment Indicator
(drupal.org/project/environment_indicator).

, , ,
. (
, ) ,
.
. 13.1
.
,
, ,
. ,

, .
.
.
?
. ,
. ,

,
. , , ,
. ,

246

13.

.
,
.
, .
,

J

(
, )

. 1 3 .1 . / ,


,
. .
Drush (drupal.org/project/drush), 25.
, , rsync.
.

,
.
, .
, ,
, .


Demonstration (drupal.org/project/demo).




( 7). .

247


. ,
, .
.
.
(. http://gitorious.org http://github.
com) .

Git ,
.
,
.
, , (
2). .git.
g it clone - -bare
( .git) (
, git.example.com, ,
/srv/git):
git clone --bare ~/code/dgd7 dgd7.git
scp -r dgd7.git you@git.example.com:/srv/git/dgd7.git

,
, :
ssh you@gitexample.com
cd /srv/git/dgd7.git
git init --bare --shared
git update-server-info


, :
cd ~/code/dgd7
git remote add origin git

,
:
ssh you@test.example.com
cd /var/www
git clone you@git.example.com:/srv/git/dgd7.git dgd7

dgd7. ,
Git- , 4.2 Pro Git (http://progit.org).
, ,

:
git add -
git commit -m "Updated pathologic module to the latest security release."
git push

, git add - (
, ) .
git status, ,
( git reset, add).

248

13.

.

(, git push origin master).
.
( Drush)
, , ,
rsync. (
).
:
ssh you@test.example.com
cd /var/www/dgd7
git pull

, Drupal,
data.agaric.com/deploying-the-agaric-way.

,
update.php, http://test.example.com/update.php.(
,
, ,
update.php .)
(

rsync) update.php, ,
.


,
.
,
.
,
.
.
, , ,
.
,
.
, .
Dmpal ,
, .
, .
,
. Chaos Tools (drupal.org/project/ctools)

. Features,
.

249

Features
Features (drupal.org/project/features) ,
.
(
), Features.
, Drupal
, Features
.
Drupal-, ,
Feature. .
Feature .
Feature ,
, .
Kit specification
drupal.org/project/kit.


. ,
Features ,
,
. Features
, Feature
.

Features Drupal 7 , ,
, , ,
. CTools .
,
. (
!) Features
. ,
CTools Strongarm (drupal.org/project/strongarm)
( Features) ,
.

Drupal ( , ,
, , . .),
Features UI Drush Feature.

Features ,
. ,
Features Feature.

Feature , ,
(reverting a feature),
, .

.

250

13.


, (hooks),
hook.
Features, , , . ,
, ,
.
: .
.
, , hook_update_N(),
hook_install() hook_schema().
api.drupal.org/hook_update_N.

,
features_revert().

API,
. ( , API, node_save(), ;
form drupal_form_submit ().)

, ,
. submit, ,
API-. , Drupal
,
drupal_form_submit(). , node_save()
drupal_form_submit().

. ,
, , .install,
. module_exists()
, .
, Feature
.
23.
dgd7.org/deploy;
Features dgd7.
org/anjali.

,
, ,
, ,
MS- Drupal.
. (
,
.)
,
.
, ( update.php).
(
, ),

251

Drupal. , Revision
moderation (drupal.org/project/revision_moderation) .

. (
Drupal 7.)
, ,
Path redirect (drupal.org/project/path_redirect). ,
Pathauto , , ,
URL-.
, ,
, Deploy (drupal.org/project/deploy).

, Feeds (drupal.org/project/feeds) Migrate (drupal.
org/project/migrate).

Node export (drupal.org/project/node_export)


, update.php
.
Pathologic (drupal.org/project/pathologic),
.


hook_menu() .
api.drupal.org/hook_menu 27.

Filter, .
().
, .
Drupal-, hook_menu(), hook_block()
hook_page_bui Id( ).

,
,
(, ).
Drupal 8,
(Universally Unique Identifier, UUID).


.
.
.
( ),
, ,
,
.
.
, ,
Features ( ).
.

252

13.

,
update.php .
,

update.php. update,
php .

( ),
.


Jenkins Continuous Integration (jenkins-ci.org). , Drupal,
groups.drupal.org/node/47686. ( 2011 Hudson.)

.
, , ,
, Features.


dgd7.org/deploy.
Anjali dgd7.org/anjali.


. ,
, ,
. Drupal ,
, .
Drupal 7
Packaging & Deployment groups.drupal.org/build-systems-changemanagement.

14.

, Drupal,

Drupal-.
, .


,
,
. , ,
.
,
.
Drupal.org
Git (http://git-scm.com). .
Git . :
git init .
git add .
git commit -m 'Initial commit.'

, g it commit -a -m
; , ,
. ,
git commit -a -m " 'd a te '" .
,
. ( , .)
;
. ,
, .
, ,
. Git
, , .
2.
"".


SQL- mysqldump (dev.
mysql.eom/doc/refman/5.5/en/mysqldump.html) Backup Migrate project (drupal.org/
project/backup_migrate). ,
Git. ,
, !
- , .
Windows Mac OS X
(Windows Backup Time Machine); Linux
( t a r sync). ,
rlsoft (r1soft.com).

254

14.


!
, .
-.
.
.
; (
12).
IRC , ...?. ,
: !
.
(, Drupal) Google,
.
, .
, , ,
.
. ,
. ,
.
, , .
. ,
, , .
, , .
! Google
, - ,
, .
; ,
.
. , ,
;
.
, .
, , (Mihaly Csikszentmihalyi),
... .
. . ,
, . ,
.
.
, , .
, (
, ).
, . ,
, , , , :
. ,
. .
,
.
. .
.

255

.
- . ,
, !
.
.
, .
, ,
.
. ,
?
. .
, . ,
, , ,
?


,
. -, ,
,
. Drupal,
( , ,
, , , ).
-, , -
. .
-, .
.
-, ,
! , .
. .
, ,
.
, ? (,
. .),
.
,
. ,
,
. , ,
. ,
. . .
, ,
.

. .
, open issues,
, .
, .
drupal.org/patch, drupal.org/patch/apply drupal.org/handbook/git.

256

14.

.
. ,
; , ,
! , .
,
.
.
, ,
. ,
needs more information ( ).
, .
, fixed ().
, , ,
Drupal, ,
.

,
, dgd7.org/think.

IV.
15 16
Drupal, .

15.

Drupal
. ,
, , XHTML-, CSS
JavaScript. , Drupal ?
.
. ,
,
.
Drupal. ,
,
.
, !
.
DGD7.
https://github.com/jacine/dgd7.


core/themes
, .
, ,
. !
. Drupal ,
- ,
.
.
Color,
. ,
, CSS-
theme. ,
; Drupal
.
,
.
, .
() .
, , ,
CSS-, , , .


Drupal . .
Bartik
Bartik , Drupal 7.
Drupal . ,

259

Color .
. 15.1. Drupal Bartik
.
j * Bartik i A them e for OrupAl 7

4-

drup al- 7 /

Home

Gravis Mauris Qui | DoiorQuia

AdipisringAt

Hue Nutia Sirtgufaris Valde |

Capto Occuro

Deseruisse referrentur cu qui, pericula assentior nec an.

Ad enim putent
Malomm mea, tc oratio
prompt voluptaria sed.
Agam anciliac inciderint usu
cu, novum maxim pro ea,
novum noniunv moiejitie vim

User login
*

Creaie i w account
Request new password

Sit affert dolores

Ei perpetua qualisque

Persequeris ad, salutandi corrumpit duo et. Iudico


perpetua ad cum, Erant regione partiendo sed an. Quod
aliquip sit cu. Vero delectus constituam eu qui, vis
aliquyam intellegam ex.

Putent defmiebas et u m ,
deifend eloquentiam no per.
Ei ullum definiebas scripscrii
pri. Ut est snroo indocturn
interesset An sed equidem
docendi, per ut solum civibus
vimperatoribiis.

Abigo Verto
puMishod by vaetophe Tu*. 01/t /2011 -08:40

Augne distineo eros manris neo vero. Caecusjugis paratus ut. Cut dolor
mos typicus, Abbas si voco. Abteo causa rat incassum lenis ludus neo
plaga quibus sac pi us. Commoveo ludus praesent. Antchabco elit exerci
persto pertineo quidnc refero typicus usitas. Amet obruo ratis vicis.
Defui facilisis ffle inhibeo nulla promo refoveo si utinam uxor.
:
pwrtwMvra

marita-sto-d

Hutt-J rtvyit t.as >nof (sflisw to ooat -

Ne duo harum possit


Nam laudem soluta equidem an, Ut nostro
recteque mel, dicarit nienandri imperdiet in
duo. Mei ait agam labors. Usu eu dissentiunt
complectitnr, sit ei sumo abhorreant.

Solet nonummy ne has


Vix vivendo s&Uitatus repudiate no, mei
audire maiomm libera visse ad. No offictis
faendrerit vel, tation munere oblique ad est,
choro aitera reprlmique ei mel

An n ih il referrentur mel
Vix id rebum elaboraret intellegebat;. Ceteros
phawirum pri ei. Duo summo minimum
urbanitas ex. Amet vitaporatoribus cu sed,
pro id novum nominal.

. 1 5 .1 . Bartik

Garland
Garland Drupal 5.
Color. . 15.2.
15 ,
.

260

15.

'

? <*G*rUnd | Drupal them*


I

drupat-7/

home

Gravfs ms Qui

Dotor Qui

Adtpiscing At

Mute Nulte Stngutans Vatde

Capto Otcuro

Garland A Drupal theme

Ad enim putent
Metorum men, te oratto prompts
votuptaria sect. Agam andtoe
tnejderint usu cu, novum maztm
pro ea, novum nonumy motestie
vim tte.

Ei perpetua quatisque

Sit affert dotores

Putent deftniebas et mea,


eietfend etoquentiam no per. ES
Hum deflnlebts scripsertt ph. Ut
est sumo indoctum interesset.

Persequeris ad, salutandi corrumpJt duo et. ludico perpetua ad cum. Erant
redone parttendo sed an. Quod aUquip sit cu. Vero delectus constrtuam eu
qui, vis altquyam inteilegam ex.

An sed equtdem docendi, per ut


solum csvibus vituperatoribus.

Abigo Tamen Verto


, 0 1 / 1 1

User login

0 ~ vaetophe

Augue distineo eros mauris neo vero- Caecus Jugts paratus


ot. Cui dolor mos typicus. Abbas si voco. Abtco causa erat

Incassum (enls ludus neo plage quibus saeptus. Commoveo


ludus praesent. Antehabeo etit exerd persto pertineo quidne refero typicus
sit as. Amet obruo ratis vicis. Defut fadhsis site inhtbeo nulla premo refoveo si
utinam uxor.

Username

>;

Create new account


Request new password

prtvubfcbra
mathaslad
Read more

&E>

tog in or register to post comments

Powered try Drupal

. 1 5 .2 . Garland, Color

drupal-7/admln/config

A<H*inir*tioft

Configuration
Hide descriptions
SYSTEM

PEOPLE

|U Site information
Change site name, e-mail address, slogan, default front page., and
number of posts per page, error pages.

: Account settings
Configure default behavior of users, including registration
requirements, e-maiis, fields, and user pictures.
;

iP address blocking
Manage blocked IP addresses.

f t Aclions

Manage the actions defined for your sae.

Cron
Manage automatic site maintenance tasks.

CONTENT AUTHORING
Text formats
Configure how content input by users is filtered, including allowed
HTML tags. Also allows enabling of module-provided fillers.

USER INTERFACE
; H | Shortcuts
Add and modify shortcut sets.

MEDIA

.................

...................................... ...................1

Filesystem
Teii Drupal where to store uploaded files and how they are accessed.

DEVELOPMENT

| | Performance
Enable or disable page caching for anonymous users and set CSS and
jS bandwidth optimization options.

Image styles
Configure styles that can be used for resizing or adjusting Images on
display.

S i Image toolkit
Choose which image toolkit to use if you have installed optional
toolkits,

SEARCH AND METADATA

Logging and errors


Settings for logging and aierts modules. Various modules can route
Dfupafs system events to different destinations, such as systog,
database, email, etc: Maintenance mode
Take the tit* offime for maintenance or bring it back online.

. 1 5 .3 . Seven

>

261

Seven
Seven, Drupal 7,
. Drupal 7 User Experience (http://d7ux.org),
Drupal.

. . 15.3.
Stark
Stark . 15.4.
HTML- CSS. , CSS- ,
.
; . ,
CSS- .
.

Stack
A them: Dropal 7

Main menu
Home

Ad ertim putent
Matorum raea, tc ornto
promprn vcluptaria scd.
A gam anciOac inciderint usu
cu, novum mazim pro ea,
novum nonumy raotestie vim
nc.

User login

AM dBE-&

Cas^Qsea

Sit affert dolores


Persequeris ad. salutandi cormmpitduo ei. Iudko pcrpetua ad cum. Erant regione partiendo scd
an. Quod aliquip sit cu. Veto deksctus constituam cu qui, vis alkjuyatn intelkgam ex.
Deseruisse refertentur cu qui, pcricuia assentior an.

m \
11* 1
m

Ei perpetua
qualisque
Putent defmiebas et mea,
elcifend eloquemiam no per.
Ei ullum defmiebas scripserit
pri. Utest sun indoctum
intcressct. An sed cquidem
docendi, per ut sohim civibus
vitupcratoribus.

Ahigo Tamen Verto


Submitted by vastopbe on Tue,01/18/2011 - 08:40
* Create new account

&E)

Augue distinco ctos mauds neo veto. Caecus jugis paraius ut. Cui dolor mos typteus. Abbas si
voco. Abico causa erat incassum lenis ludus neo plaga quibus saepius. Commoveo ludus
praesent, Antehabeo clit cxcrci pcrsto pertinco quidne refero typicus usitas. A met obroo ratis
vicis. Deftii facffisis ilk inhibeo nulla premo refoveo si utinam uxor.

Tags:

maftaslael

Read more

Log in or register to post comments

Powered by

. 1 5.4. Stark


theme engines, PHPTemplate.
,
PHP-. PHPTemplate

262

15.

. , ,
,
, .
, Smarty, XTemplate PHPTal,
Drupal (
, ),
. , Drupal
.
Chameleon, http://drupal.org/project/chameleon.
http://drupal.org/project/theme+engines.


Appearance Drupal.
,
( Color) .

,
Drupal 7 ,
Appearance, Bartik,
, . 15.5. ,
? Drupal ,
.
,


Bartik 7.0 (default theme)

A flexible, recolorabie th em e w ith m any regions.


Donee itib .

Settings

,

Seven .

__
,


Seven 7.0
A sim ple o n e -c o lu m n , tab lele ss, fluid w idth ad m in istratio n them e.

Settings

pijiable-' Set default

Set
default ....
Seven ,

. 1 5 .5 . Appearance Drupal

, , ,
.
, SwitchTheme (http://
drupal.org/project/switchtheme), ,
.

263


Drupal 7 Seven.

, /admin.
.
Drupal ,
.
admin/
appearance. ,
Drupal, ,
.


, ,
. ,
. Global Settings (. 15.6)
admin/appearance/settings.
. ,
admin/appearance. ,
, .
, .
TOGGLE DISPLAY
Enable or disable the display of certain page elements.

0Logo
Site name
Site slogan
{Sf User pictures in posts
0 User pictures in comments
User verification status in comments
0 Shortcut icon
0 Main menu
Secondary menu

I
LOGO IMAGE SETTINCS
If toggled on, the following logo will be displayed.
0 Use the default logo
Check here if you want the theme to use the logo supplied with it,

SHORTCUT ICON SETTINGS


Your shortcut icon, or 'favicon', is displayed in the address bar and bookmarks of most browsers.
Use the default shortcut icon.
Check here if you want the theme to use the default shortcut icon.

. 1 5 .6 . Global Settings

264

15.

,
. 15.6 , .
.info .
. .info
,
, .
, .info:
features[]
features[]
features[]
features[]
features[]
features[]
features[]
features[]
features[]

=
=
=
=
=
=
=
=
=

logo
name
slogan
favicon
main_menu
secondary_menu
node_user_picture
comment_user_picture
comment_user_verification

Drupal logo, png theme.


.
Logo $logo
page. t p l . php. .

. ,
admin/config/system/site-information.
. page.tpl.php
$site_nam e $ s ite _ s lo g a n .

,
. ,
. , ,
misc/favicon.ico.

User pictures in posts User pictures in comments ,
$ u s e r_ p ic tu re node.tpl.php { p ic t u r e
comment.tpl. php, np/h
() .

User Verification Status in Comments
, , Not verified.
tem plate__preprocess_usernam e()
theme_username( ) {v a ria b le s [ e x t r a ' ] . , ,
.

Main menu Secondary menu , Jmainjnenu
$secondary_menu page.tpl.php

265

. admin/structure/
menu/settings , .
Jmainjnenu Main menu,
admin/structure/menu/manage/main-menu.
User menu, admin/
structure/menu/manage/user-menu.

, theme_links () ,
tpl.php ( ).
. ,
.
Menu Block (http://drupal.org/project/menu_block),
, .

,
. , Garland garland.info
garland_width, fixed fluid. Shortcut
, Add or remove shortcut link
( ). ,
, Seven.
http://drupal.org/node/177868.


Drupal ,
, Drupal .
/themes, ,
. ,
. , Drupal
, ,
:
sites/all/themes ,
Drupal:
s\\es/UMH_caiima/\hemes ,
.

. Install new theme
Appearance. ,
, Install.
sites/all/themes directory.
admin/admin/appearance page.


.info , , Drupal,
,
. .info .
,
Drupal .
. , ,

266

15.

.info . , themename.
info, theme_name.info.
, . ,
,
themename_menu_link(), theme_name_menu_link().

.
, ,
, -.

.info . , ,
, , .
.

.info , .
:
; . . .

core. Drupal , core


. , 6.x, 7.x 8.x:
core = 7.x

name. . ,
:
name =

base theme. Drupal . ,


(
).
:
base theme = themename

description.
. , , admin/
appearance HTML-.
description =
engine. . PHPTemplate,

, . smarty theme ( , . Chameleon http://


drupal.org/project/chameleon).
engine = phptemplate
features.

Drupal. .
Settings .

267

, , ,
. info.
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []
fe a tu r e s []

=
=
=
=
=
=
=
=
=

logo
favicon
name
slogan
node_user_picture
comment_user_picture
com m ent_user_verification
mainjnenu
secondary_menu

php. Drupal 7 5.2.5.


. , ,
, ,
, , .
php = .3

re g io n s . ,
.
reg io n , .
, , :
reg io n s [_] = _6_

, :
regions[page_top] = Page Top
regions[header] = Header
re g io n s [h ig h lig h te d ] = H ig hligh ted
re g io n s [h e lp ] = Help
reg io n s[co n ten t] = Content
re g io n s [s id e b a r_ fir s t] = Sidebar F ir s t
regions[sidebar_second] = Sidebar Second
re g io n s [fo o te r] = Footer
regions[page_bottom] = Page Bottom

s e tt in g s .
. , Garland
(fixed fluid).
,
Omega ( http://drupal.org/project/omega) Fusion ( http://drupal.org/project/fusion)
, .
http://drupal.org/node/177868.
s e ttin g s [g a rla n d _ w id th ] = f lu id

screenshot. screenshot.png ,
, Drupal theme.
,
.
294x219 .
screenshot = screenshot. png

s ty le s h e e ts . CSS- Drupal 7 .
, ,
.info . .

268

15.

stylesheets[screen][] = path/to/screen-stylesheet.css
stylesheets[print][] = path/to/print-stylesheet.css

scripts. JavaScript-
.info. ,
, .
scripts[] = path/to/script.js

version. ,
. Drupal.org ,

.
.
version = 7.-1.1

.info DGD7 ( 15.1).


1 5 .1 . .info DGD7

name = DGD7 Theme


description = A theme written for The Definitive Guide
to Drupal 7 book website,
core = 7.x

core,
admin/appearance , . 15.7. ,
, , .
DGD7 Theme
A them e written for The Definitive Guide to Drupal 7 book w ebsite.
Settings

Disable

Set default

. 1 5 .7 . DGD7 admin/appearance


, , , .
1. dgd7 sites/all/themes.
2. dgd7 dgd7.info
:
name = DGD7 Theme
description = A theme written for The Definitive Guide
to Drupal 7 book website.
core = 7.x

3. screenshot, png dgd7.


. No screenshot.
4. admin/appearance .
Disabled Themes. Enable and set default,
.

269

.info, !
admin/config/development/performance.


Drupal .
(header), (footer), (sidebars)
(content), . 15.8;
HTML-.
admin/structure/block.
.
BLOCK

OPERATIONS

Disabled

. 1 5 .8 .

Bartik

270

15.

.
. 15.9 Bartik.
AWock( the header.
'

B a r tik
A thermp r Orupat 7

>
Home

Gravis Mauris Qui

Odor Gtia

Adiptsdng At I Hue Nulla Stnguiaris Vatde

Gapto Occuro

. -

Heres a block in the featured region.

Sidefar first
Malonun moa, te oratio
prompta voluptaria sed.
Agam aneillae inekkrint usu
cu. novum matira pro ea,
novum nonumy molestie vim
no.

Sidebar second

H ighlighted region

Putent definiebas et mea,


eicifend doquentiam no per,
Ei ultum definiebas scripserii
pri. Ut st sun mdoctum
rareresset, An sed equidem
docendi, per ut solum civibus
vituperatoribus.

Persequeris ad, salutandi cornimpit duo et.

Help
Minim quam tation quod gothiea in.

User login
Username *

Abigo Tamen Verto


| * pubiistred by vastophe on Tue, 01/18/201 i -08:40

Password '

* Create new account


Request new password
L09 in

Augue distineo eros mauris neo vero. Caecus jugis paratus ut. Cui dolor
mos typicus. Abbas si voco. Abico causa erat incassum lenis Indus neo
piaga quibus sacpius, Commoveo ludus praesent. Antehabeo eiit exerci
persto pertineo quidne refero typicus usitas, Araet obruo ratis vicis.
Defui faeffisis ilie inhiheo nulla premo rcfoveo si utinam uxor.
Tags:
finwubefefa mtteasfee!
more Log h or neater te post

m
T riptych firs t
Nam iaudem soluta eqaidem an. Ut nostro
recteque mei, dicant menandri imperdiet in.

T rip tych m iddle


Vsx vivendo alutatus repudiare no, mei
aadire maioram Hberavjsse ad. offidis.

T riptych last
Vix id rebum elaboraret inteiiegebab Ceteros
phaedrum pri ei. Duo summo minimum.

. 1 5 .9 . Bartik,

271

,
JavaScript- j Query-.

.

,
Drupal ,
. 15.2
.info. , ,
, .
Drupal , .
,
.info.
1 5 .2 .

regions[page_top] = Page Top


regions[header] = Header
regions[highlighted] = Highlighted
regions[help] = Help
regions[content] = Content
regions[sidebar_first] = Sidebar First
regions[sidebar_second] = Sidebar Second
regions[footer] = Footer
regions[page_bottom] = Page Bottom

.info .
, , .
,
( ). ,
. ,
page_top, content page_bottom, . Drupal-
. 15.3
.info, ,
.
1 5 .3 . .info

; CORE REGIONS - DISABLED


;regions[highlighted] = Highlighted
;regions[help] = Help
;regions[header] = Header
;regions[footer] = Footer

; CORE REGIONS - REQUIRED


regions[pagejtop] = Page Top
regions[content] = Content
regions[page_bottom] = Page Bottom
; CORE REGIONS
regions[sidebar_first] = Sidebar First
regions[sidebar_second] = Sidebar Second

; CUSTOM REGIONS
regions[my_custom_region] = My Custom Region

272

15.

, Drupal , ,
_system_rebuild_theme_data() http://api.drupal.org/_system_rebuild_theme_data.

. 15.10, Drupal
. ,
. header, sidebar_first, sidebar_second footer .
page_top page_bottom ;
.

header
highlighted
help

. 1 5 .1 0 . , Drupal

h ig h lig h te d ,

page.tpl.php. ,
, .
, .
h ig h lig h te d .
h elp page.tpl.php,
. ,
help. ,
, content ,
main co n ten t.

c o n ten t Drupal 7.
, , ,
. Block ,
main page c o n te n t Drupal,
$ p a g e [' c o n te n t ' ] page.tpl.php.

273

Block
. main page co n ten t
, ,
. ,
: , ,
CSS-, .


. 15.8
page_top page_bottom. , Drupal
, -
. ,
. .info.
, .
:
regions_hidden[] = the_region_name

, page_top page_bottom, html.tpl.php ( 15.4)


, . , page_top region
Toolbar ,

. page_bottom
, . ,
Google Analytics JavaScript-,
, .
page_bottom $closure,
Drupal.
1 5 .4 . html.tpl.php, page_top

page_bottom
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlilang ="<?php print {language->language;

?>"
version="XHTML+RDFa 1.0" dir ="<?php print {language->dir; ?>"<?php print $rdf_
namespaces; ?>>
<head profile="<?php print {grddl_profile; ?>">
<?php print {head; ?>
<titlex?php print $head_title; ?></title>
<?php print {styles; ?>
<?php print {scripts; ?>
</head>
<body class="<?php print {classes; ?>" <?php print {attributes;?>>
<div id="skip-link">
<a href="#main-content" class="element-invisible element-focusable"><?php print
t('Skip to main content'); ?></a>
</div>
<?php print {page_top; ?>
<?php print {page; ?>
<?php print {page_bottom; ?>
</body>
</html>

274

15.

page_top page_bottom Drupal


hook_system_info_alter(). http://api.drupal.
org/api/function/system_system_info_alter/7.

,
, , Dashboard Main
Dashboard Sidebar, Dashboard.
. .
Dashboard h o o k _ s y s te m _ in fo _ a lte r( ),
.
,
, . 15.11.

. 1 5 .1 1 . Dashboard


, ,
.
, , ,
, ,

275

. ,
, . .info
, , 15.5,
.
1 5 .5 . , Drupal

regions[page_top] = Page Top


regions[header] = Header
regions[highlight] = Highlight
regions[help] = Help
regions[content] = Content
regions[sidebar_first] = Sidebar First
regions[sidebar_second] = Sidebar Second
regions[footer] = Footer
regions[page_bottom] = Page Bottom

.info ,
. page_top page bottom html.tpl.php,
page.tpl.php. , , .

:

, , ,
, ,
, ,
. . ,
. , .
,
.

. ,
. ,
CSS- . ,
, , ,
, . ,
, .

.
,
page.tpl.php,
.
,
. ,
.

($main_menu)
(Ssecondary menu) page.tpl.php.

276

15.


(Sidebar First Sidebar Second)
c la s s body .
Drupal .
, . Drupal
, ,
.
, , , ,
, Sidebar First
. ,
, Sidebar First ,
. ,
CSS-, ,
. ,

CSS- .
,
(, ). .
.
,
. , ,
. CSS-
, . 15.12 ,
.
page_top

banner_;

sid eb ar_secon d

navigation

footer
p age_b ottom

. 1 5 .1 2 .

277

,
.
, ,
, .
. 15.13 Bartik,
.
(Footer First Footer Second)
CSS-.
Bartik, 15.6, ,
, .
1 5 .6 . .info Bartik,

regions[triptych_first] = Triptych first


regions[triptych_middle] = Triptych middle
regions[triptych_last] = Triptych last
regions[footer_firstcolumn] = Footer first column
regions[footer_secondcolumn] = Footer second column
regions[footer_thirdcolumn] = Footer third column
regions[footer_fourthcolumn] = Footer fourth column

. 1 5 .1 3 . Bartik


.
. 15.12,
.
1. dgd7.info.
, 15.3.
banner_ad n a v ig a tio n :

278

15.

; DEFAULT REGIONS
regions[page_top] = Page Top
regions[header] = Header
regionsfhighlight] = Highlight
regions[help] = Help
regions[content] = Content
regions[sidebar_first] = Sidebar First
regions[sidebar_second] = Sidebar Second
regions[footer] = Footer
regions[page_bottom] = Page Bottom
; CUSTOM REGIONS
regions[banner_ad] = Banner Ad
regions[navigation] = Navigation

2. page.tpl.php.

admin/structure/block. ,
page.tpl.php .
modules/system, page.tpl.php
sites/all/themes/dgd7.
page.tpl.php, <div id="pagewrapper">
<div id="header"> :
<div id="page-wrapper"xdiv id="page">
<?php print render($page['banner_ad']); ?>
<div id="header"xdiv class="section clearfix">

$main_menu
.
:
<?php if ($main_menu || $secondary_menu): ?>
<div id="navigation"xdiv class="section">
<?php print theme('links_system_main_menu', array('links' =>
$main_menu, 'attributes' => array('id' => 'main-menu', 'class' =>
array('links', 'inline', 'clearfix')), 'heading' => t(
'Main menu'))); ?>
<?php print theme('links_system_secondary_menu', array('links' =>
$secondary_menu, 'attributes' => array('id' => 'secondary-menu',
'class' => array('links', 'inline', 'clearfix')), 'heading' =>
t('Secondary menu'))); ?>
</divx/div> <!-- /.section, /#navigation -->
<?php endif; ?>

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

3. , .
. Banner Ad
, (
Full HTML). Region
Settings Banner Ad .
<img style="width: 728; height: 90; border: solid lpx #000;"
alt="728 x 90 Banner Ad" src="image.png" />

admin/structure/block. Main Menu,


Navigation Save blocks.
!

279


Drupal,
. HTML-
PHP-. , ,
.

Heres a block in the featured region.

Sidefar first
Malomm mea, te ratio
prompt voiuptaria sed.
Agam andilae icckfeint usu
cu, noviim mazim pro ea,
novum nomtmv rooks tie vim

Sidebar second

[Highlighted region
Persequeris ad,

P$em defimehas et mea.


elejfend eloquentfam no per,
Ei ulium definiebas seripserir
pri, Ut est sumo mdoctam
intaressei> An sed equicfem
docends. per ut solum civibas
viffiperatoribtst.

salutandi corrumpit duo et.

.Help
Minim quam Saturn quod gotbica ut

User login
I'ltfl'tllUBlS *

Cis-ste account

JtequfiirtnewpMmori

node.tpl.php 1

iAbigo Verto

'1 en . s# 11- - qu a
d

iAugue distineo eros maem neo vero. Caecusjisgb parali field.tpl.php 8


ireos typicus. Abbas si voco. Abico causa erat incassum leieus iu o u s neo ;
jpiaga quibus saepius, Coramoveo iudus praesent. Anteh;ibeo eiit exerci j
S
Ipersto pertineo quidne refero typicus usitas. Amet obrutsrat is vk-is.
jEteiui faeilisis iUe inhibeo nulla premo refovco si utinam uxor.
field.tpl.php |

[:

prtfufeeft'a .
mar* Uogft of &

Triptych first

" r 'v

I i

%4'am laudem soiuta eqoidem an. Ut nostro


Vecteque mel, dieant men&ndri imperdiet in. *

to pettojnwerts

Triptych middle

Triptych last

<

4% id. rebum elalxiraret intellegebat. Ceteros*


jphaedrum pri ei, Dno sumrno minimum.
j

Kruc vivendo saiutatus repudiare no. i


imdire maiorum liberavisse ad. No offsciis.

....................... 1block.tplphp 1 J.......................1blodc.tpl.php 1 1...................... 1block.tpl php I


t

l!

. .15.14. , Bartik,

280

15.

15.7 user-picture.tpl.php.
modules/user
( ,
).
<div class="user-picture">. ,
user_picture,
(, ).
1 5 .7 .

user-picture.tpl.php

<?php
// $Id: user-picture.tpl.php,v 1.5 2009/08/06 05:05:59 webchick Exp $

/**
* @file
* ,

*
*
*
*
*
*
*

:
- $user_picture: .

.
- $account: . .
check_plain().

* @see template_preprocess_user_picture()

*/
?>
<?php if ($user_picture): ?>
<div class="user-picture">
<?php print $user_picture; ?>
</div>
<?php endif; ?>

Drupal
. . 15.14,
, html.tpl.php page.tpl.php,
field.tpl.php, .


Drupal ,
( . 15.1).
Drupal-,
.
1 5 .1 . 1

html.tpl.php

modules/system

HTML-,
<head>, $scripts
$styles <body>
$page_top, $page
$page_bottom.
,
DOC7YPE

1 field.tpl.php . ,
modules/field/theme, .

281

page.tpl.php

modules/system


, $logo, $site_name, $tabs,
$main_menu . .
.

region.tpl.php

modules/system

HTML-

block, tpl. php

modules/block

HTML-

node.tpl.php
comment.tpl.php

modules/node

HTML-

modules/comment

HTML-

field.tpl.php1

modules/field/theme

HTML- .
, ,
.
,


, Drupal ,
, . (
) .
, , ,
, . Drupal
, .
, .
:
1. , http://api.drupal.org.
2. theme.
3. !
Drupal ,
. .

, Drupal , ,
, Hello, World.
, .


, .
. , ,
. ,
, . 15.2 (
, HTML-). ,
, .
1 5 .2 . ,

$is_admin

, TRUE,

&

282

15.

1 5 .2 ()

$logged_in

, TRUE
.
$user->uid,
, 0

$is_front

, drupal_is_front_
page() .
TRUE, (
), FALSE

$directory

$user

,
. ,
, global $user;
,
, ,
.
themeCusername');, , themeCusemame, array(account' =>
$user))

Slanguage

, ,
. , Slanguage->dir
. $language->language,
, .
global Slanguage;

$theme_hook_suggestions

, ,

, . .

$title_prefix $title_suffix

, ,
. ,

HTML-
Drupal 7 .
RDF,
. ,
.
, . 15.3,
. _.
,
template_preprocess() template_preprocess_node() template_preprocess_block().
, template_process()
, .
. 15.15.
16.

, . 15.15, ,
RDE

283

1 5 .3 . HTML-

$attributes

HTML-, (
RDF), class.
$attributes $attributes_
array HTML-
, <bady> <div>

$classes

HTML- .
HTML- , <body>
<div>

$title_attributes

,
. <h2>

$content_attributes

<div> .
node.tpl.php

$attributes_array

$classes_array

attribute*_array [Army, 2 &&)

1_* {, 3 )

0 (Srtng, 4 characters) notit

about {String, 1$ characters}/?q*nod*32-articte

1 (Ssing, 12 characters)

typt*of{Amy, 2et&m&nts)

v.

2 [String. 13 characters} node-promoted

flSiti

$classes

0 {String, 9 characters) stoc:Ji*m


1 (Siring, 13 characters} foaf: Document

$attributes

<div id=Knode-l" class-1*node node-article node-promoted node-teaser clearfix"

.. .. ................_ */ ....J k r i T l \

. T.f

about='7?q=node/l" typeof=sioc:Item foaf:Document">


<h2 property="dc:title" datatype='>
<a href="/?q=node/l">My Article Title</a>
</h2>
<div class="content1^...</div>

f
</div>

\ 4

$title_attributes_array
tjtie^itHjtes_array (Amy, 2 elements)
property {Array, 1 element}
0 (String, 8 characters) dcitfde
datatype (String, 0 characters)

$content_attributes_array

$title_attributes

contentattributesarray (Army, 0 elements)


$content_attributes

. 1 5 .1 5 . node.tpl.php,

HTML-

,
. , , block.tpl.php,
modules/block, , .
15.8 , .

284

15.

15.8. modules/block/block.tpl.php,

<?php

/**

* @file
* , .

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

:
- $block->subject: .
- $content: .
- $block->module: ,
- $block->delta: , .
- $block->region: , .
- $classes: ,
CSS. $classes_array
. :
- block: , "theming hook".
- block-[module]: , . , user
.
"block-user".
- $title_prefix (array): , ,
,
.
- $title_suffix (array): , ,
,
.

* :
*'- $classes_array: html.
* $classes.
* - $block_zebra: 'odd' 'even' .
* - $zebra: $block_zebra, .
* - $block_id: , .
* - $id: $block_id, .
* - $is_front: true, .
* - $logged_in: true .
* - $is_admin: true, .
* - $block_html_id: HTML.

* @see template_preprocess()
* @see template_preprocess_block()
* @see template_process()

*/
?>
<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print
$attributes; ?>>
<?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
<h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
<?php endif;?>
<?php print render($title_suffix); ?>
<div class="content"<?php print $content_attributesj ?>>
<?php print $content ?>
</div>
</div>

(frfile block .
, ,

285

. @see
, .
, ,
, Bartik. block.tpl.php;
Drupal-, Block.
Custom Block .
Sidebar First Bartik.
, . 15.16, block.tpl.php,
15.9, .
<?php p rin t $block->subject ?>, <?php p rin t {content ?>.
Drupal ,
.
*

j* My Custom Block

'A custom * block

Rnim quam iusto quam iis


enim. Molestie at et diam ut
legere. Feugiat tation
' ' facilisis quarta soluta quam.
Facilisis lectorum modo nam
roodo suscipit.

Block description *
A custom block
A brief description of your , Used on the Blocks administration page

Block tie
My Custom Stock

17?

The title of the block as shown to the user.

Block body *
ftjiflJ quam Iusto quam iis enim. Moleetie at et diam ut legere Feuftiat tat)on fadiisis quarta soiuta quam. Fadiisis
lectorum nxxto nam modo

: Text format

More information about text formats #

: Web page addfesses and e-m ail addresses turn into links automaticaliy,

Aiiowcd HTML tags: <a> <em> <&trong> <dte> <biockquote> <code> <uS> <o)> <ii> <di> it> <dd>
* Lines and paragraphs break automatically

The content of the block as shown to the user.


REGION SETTINGS

Specify in which themes and regions this block is displayed.


Bartik

. 1 5 .1 6 . , Bartik,

1 5 .9 . HTML- My Custom Block,


<div id = " b lo c k -b lo c k -l" class="block block-block">

<h2>My Custom Block</h2>


<div class="content">
<p>Enim quam iusto quam iis enim. Molestie at et diam ut legere. Feugiat tation
facilisis quarta soluta quam. Facilisis lectorum modo nam modo suscipit.</p>
</div>
</div>

15.10 HTML- ,
, . .
, Contextual Links.
<?php p r i n t r e n d e r ( $ t i t le _ p r e f ix ) ; ?>. Contextual

286

15.

Links <div>,
. Block block.tpl.
php. $title_pref ix $title_suffix
, Contextual links.
1 5 .1 0 . HTML- My Custom Block,
. $title_suffix

<div id="block-block-l" class="block block-block contextual-links-region">


<h2>My Custom Block</h2>
<div class="contextual-links-wrapper contextual-links-processed">
<a class="contextual-links-trigger" href="#">Configure</a>
<ul class="contextual-links">
<li class="block-configure first last"xa
href="/admin/structure/block/manage/block/l/configure?destination=node">Configure
block</ax/li>
</ul>
</div>
<div class="content">
<p>Enim quam iusto quam iis enim. Molestie at et diam ut legere. Feugiat tation
facilisis quarta soluta quam. Facilisis lectorum modo nam modo suscipit.</p>
</div>
</div>


, , HTML-,
( ). Drupal
, ,
.
Drupal 7 http://api.drupal.0rg/api/gr0up/themeable/7 .


Drupal ,
.
hook_theme().
.
, hook_theme() 15.11.
1 5 .1 1 . hook_theme()

<?php

/**
* hook_theme().

*/

function mymodule_theme() {
return array(
,my_theme_hook' => array(
'variables' => array('parameter' => NULL),

),
);
}
?>
hook_theme() Drupal .
Drupal theme_my_theme_hook(),
, 15.12.

287

1 5 .1 2 .

<?php
function theme_my_theme_hook($variables) {
$parameter = $variables['parameter'];
if (!empty($parameter)) {
return '<div class="my-theme-hook">' . $parameter . '</div>';

}
>
?>


theme_this() theme_that().
, .
,
, , ,
, , . .
theme(),
. , ,
http://api.drupal.0rg/api/functi0n/theme/7 .
15.13 15.14 theme_image()
.
1 5 .1 3 .

<?php print theme('image', array('path' => 'path/to/image.png', 'alt' => 'Image


description')); ?>
1 5 .1 4 .

<?php print theme_image(array('path' => 'path/to/image.png', 'alt' => 'Image


description'));

?>



. ,
template.php. :
1. Drupal http://api.drupal.org.
2. template.php.
3. theme_ .
4. template.php, !

template.php <?php.
, .
,
Cannot modify header information ( ) Headers
already sent ( ).
http://drupal.org/node/1424.


theme_more_link().
. http://api.drupal.org/api/function/
theme_more_link/7.

288

15.

1. template.php:
< ?php

/**
* HTML- "more", .

*
*
*
*
*

@param $variables
:
- url: url- .
- title: , 'Read more'.

*/
function theme_more_link($variables) {
return '<div class="more-link">' . l(t('More'), $variables['url'],
array('attributes'
=> array('title' => $variables['title']))) . '</div>';

}
?>
2. , :
< ?php

/**

* HTML- "more", .

*
*
*
*
*

( $variables
:
- url: url- .
- title: , 'Read more'.

*/
function dgd7_more_link($variables) {
return '<div class="more-link">' . l(t('More'), $variables['url'],
array('attributes'
=> array('title' => $variables['title']))) . '</div>';

}
?>
3. Drupal , !
<?php

/**
* theme_more_link().
* - "More" "Show me More"
* - "more-link" "more"

*/
function dgd7_more_link($variables) {
return '<div class="more">' . l(t('Show me MORE!'), $variables['url'],
array('attributes' => array('title' =>
$variables['title']))) . '</div>';

}
?>

3 ,
. ,
, . ,
.
, ,
Drupal 7 Drupal 8.

289


,
(hooks).
.
.


Drupal ,
hook_theme(). ,
-, . ,
,
, .

.
, .
, ,
. , ,
, ,
.
, Drupal
,
. ,
.
, . ,
node.tpl.php theme_node()
node. , ,
.
,
,
. node,
template_preprocess_node(), yourtheme_preprocess_node().



, . , ,
. ,
block.tpl.php,
. ,
, ,
, .

, .
, .
$theme_hook_suggestions,
.

290

15.


, . 15.4,
. ,
Drupal 15.15
te m p la te _ p re p ro c e s s _ b lo c k ().
1 5 .1 5 . template_preprocess_block(),

<?php
$ v a r ia b le s [ theme_hook_suggestions' ] [ ] = 'blo ck__' .
$ v a ria b le s [ ' b lo c k ' ] - >region;
$variables['them e_hook_suggestions' ] [ ] = 'block__' .
$ v a r ia b le s ['b lo c k ' ]->module;
$variables['them e_hook_suggestions' ] [ ] = 'blo ck__' .
$ v a ria b le s ['b lo c k ']-> m o d u le . '__' .$ v a r ia b le s ['b lo c k '] -> d e lt a ;

?>
Drupal
, , . ,
. 15.4.
1 5 .4 .

Block

block.tpl.php

block_REGION

block--REGION.tpl.php

REGION
,

block_MODULE

block--MODULE.tpl.php

MODULE
. , ,
,
blockblock.tpl.php, ,
menu,
block-menu.tpl.php

block MODULE
DELTA

block--MODULE--DELTA.tpl.php

DELTA,
,
,
. ,
Navigation, System,
block-- systemnavigation.tpl.php.
MODULE
system, DELTA navigation


- , ,
html.tpl.php page.tpl.php .
them e_get_suggestions ( ) .

. , , ,
,
page.tpl.php.
,
. Drupal .
, URL- http://yoursite.eom/node/1, node, 1.

291

Drupal Drupal.

.
. 15.17 ,
page.tpl.php html.tpl.php .

( page.tpl.php html.tpl.php)

()
,

$theme_hook_suggestions
$theme_hook_suggestions

http://yoursite.com/

http://yoursite.com/

http://yoursite.com/

user/1
http://yoursite.com/

whatever/lwant
http://yoursite.com/

whatever/1


.
,

------- page-node.tpl.php-------- > page.tpl.php

node*
node/1

(
)

- ->> page-node-1.tpl.php------ >

pagenode%.tpl.php------- page--node.tpl.php-----------> page.tpl.php

- -> page-user-1.tpl.php------>

pageuser%.tpl.php-------- >> pageuser.tpl.php----------- >

- - V page-whatever-lwant.tpl.php...........................................- > page-whatever.tpl.php -

- -> page-whatever-1.tpl.php -


1- 2-

, ,

page-whatever-%.tpl.ph|* -

%

2- .

1-
2-

page.tpl.php

page-whatever.tpl.php - - page.tpl.php


1- ,

/.
,

. 15.17. page.tpl.php
Drupal node ,
Configuration Site Information. ,
, . ,
node_page_def ault (). , Promote to
front . front .
.

. 15.17 , , ,
, views panels.
.
, ( Pathauto), about/team
node/1, . ,
.
.

$theme_hook_suggestions :
.

292

15.

, ,
. .
, theme () ,
, .
hook ( ).
15.15 block. Drupal
, block- -module, tp l. php, ,
block, block.tpl.php.
$theme_hook_suggestions ,
/ .
, . ,
$theme_hook_suggestion. ,
$theme_hook_suggestions.

dpm()
( Devel). <?php dpm($theme_hook_suggestions); ?>
.


,
$theme_hook_suggestions
. , , ,
, .
.
, .
,
theme_links(),
.
, , Drupal
, theme_links().
,
, .

theme_links(). , ,
, , .
. 15.5,
THEME template.php.
15.5. theme_links()

Links

THEME_links()

links_node

THEMEJinks_node()

links_comment

TH EM EJ inks_com ment()

no ,
,

theme_
links(),

theme_
links(),

293

links_contextual

THEM Jinks_contextual()

links_contextual_
node

THEMEJinks_contextual_node()

theme_
links(), ,

theme_
links(),

page.tpl.php, modules/system,
, ,
. theme_links system_main_menu()
theme_links__system_secondary_menu(), .
, theme_links(),
15.16.
15.16. modules/system/page.tpl.php

<?php if ($main_menu || $secondary_menu): ?>


<div id="navigation"xdiv class="section">
<?php print theme('links_system_main_menu', array('links' => $main_menu,
'attributes' => array('id* => 'main-menu', 'class' => array('links', 'inline',
'clearfix')), 'heading' => t('Main menu'))); ?>
<?php print theme('links_system_secondary_menu', array('links' => $secondary_menu,
'attributes' => array('id' => 'secondary-menu', 'class' => array('links, 'inline',
'clearfix')), 'heading' => t('Secondary menu'))); ?>
</divx/div> <!-- /.section, /#navigation -->
<?php endif; ?>

.
themeQ,
theme_links__system_mainjnenu().
.
theme_links(). theme()
.

, .
. ,
,
hook_theme(). ,
THEME_preprocess_page(), _
preprocesspage__front().

Drupal, :
.info .
.
.
,
.

16.

Jlyucu

Drupal .
: .info, .
, .
.
,
,
(render API).
CSS-,
Drupal. .


, , ,
, . , ,
,
.
.
.
p r i n t _ r ( ). var_dump( ), get__def in e d _ v a rs ( )
Drupal- debug( ).
, Drupal .
,
. , Devel ( http://drupal.org/project/devel) Krumo
.
Devel, , dpm() k p r ( ).

{ v a r ia b l e s dsm () dsm ().
<?php d p m ($ v a ria b le s ) ; ?> node.tpl.php,
. 16.1.
... {, 60elements)
Krumo version 0 .2 .1 j httpJ/kromo.courceforge.nei
Called from / U s e r s / j a c i n e / S i t s / d r u p a l - 7 / s i t e s / o l l / t h e * e s / a p r e s s / t e p l o t < s

. 1 6 .1 . <?php dpm($variables); ?> node.tpl.php

dpm() ,
{messages page.tpl.php, ,
. . 16.2, ,
.
.
. , { v a r ia b le s [ ' s ta tu s ' ]

295

$s ta tu s .
, { v a r ia b l e s [ 's t a t u s ' ].
(Array, 60 elements)

vid (String, 2 characters) 45


uld {String. 2 characters) 46
title (String, 17 characters) Gravis Mauris Qui
tog (String, 0 characters)
status (String11 characters) 1
comment (String, 1 characters) 0
promote (String>1 characters) 0
sticky (String, 1 characters }Q
nid (String, 2 characters) 45
type (String, 4 characters}page
language (String, 3 characters) und
created (String, 10 characters) 1295203097
changed (String, 10 characters}1295421670
tntd (String, 1 characters) 0
translate (String, 1 characters) 0
revision Jtimestamp (String, 10 characters) 1295421670
revjslon_uid (String. 1 characters) 1

'

rdf_mapplng (Army, 9 elements)


cid (Integer) 0
!ast_comment_timestamp (String, 10 characters) 1295203097
iast_comment_name (String, 0 characters}
last_comment_uid (String, 2 characters} 46
comment_count (integer) 0

. 16.2. , dpm()

Theme Developer
Drupal, , . Theme Developer
( http://drupal.org/project/devel_themer).
.
.
. ,
, . 16.3.
, :
, ;
();
;
.

296

16.

My node
View
tm portunus odio sino iorqueo veniarn. Esse loquor neo occuro similis. Apt*
duis elit jum entum sudo vicis zelus. A liquip consectetuer convervtio defui e\

nobis

region p.\<j htn

pneul

iico abigc

s i t e s / a ll/ t h e m e s / a p r e s s /t e m p la t e s /n o d e ,t i
node

37

rcorie.payi?

:empiatf jK tp ro ce si
rtif_prepfocesiRotie

Sec turpis

ssie s / atl/t hem>s/ap res*/templates/node. tpl. php

tempteiej3reproctss.node

cORtextuaS..prepfOces%

corper
noveo irii
las mos ni
tam en t

apre!spfeprocs^..node

rem platejHocebi '* rd?,vprocess

os Ib ider
voco.
J uutinam
ti
S m rn o v e rs io n 0 -2 ,l a I KttpJ/krumo.ourc*foro*.r>*t

Issuscipit.
us

Incassum occuro suscipit utrum . Acsi autem defui distineo facilisi im puto q

& jaa la.

. 16.3. Theme Developer


( )


.
, ,
. , ,
,
. .
,
. ,
. , ,
, .
.
, , Drupal: !
. , ,
. , ,
. Drupal 7
, .
Drupal
$classes_array {classes variables. 16.1 template_
preprocessQ, ,
,
$classes__array (. http://api.drupal.Org/api/function/template_preprocess/7).

297

1 6 .1 . template_preprocess(),

$classes_array
<?php
function template_preprocess(&$variables, $hook) {
// class .
$variables['classes_array'] = array(drupal_html_class($hook));

}
?>
, ,
. , ,
node.
, .
Node, tem plate_preprocess_node()
(. http://api.drupal.0rg/api/functi0n/template_prepr0cess_n0de/7 ). 16.2,
.
16.2. template_preprocess_node(),

$classes_array
<?php
function template_preprocess_node(&$variables) {
// .
$variables['classes_array'][] = drupal_html_class('node-' . $node->type);
if ($variables['promote']) {
$variables['classes_array'][] = 'node-promoted';

if ($variables['sticky']) {
$variables['classes_array'][] = 'node-sticky';

>

if (!$variables['status']) {
$variables['classes_array'][] = 'node-unpublished';

>

if ($variables[teaser']) {
$variables['classes_array'][] = 'node-teaser';

if (isset($variables['preview'])) {
$variables['classes_array'][] = 'node-preview';

>
}
?>
template_preprocess_node()
, .
.
Drupal :
template_process() rdf_process(), RDF.
template_process() ,
, $classes. ,
$classes_array. {classes
class <div> node.tpl.php, 16.3.
16.3. template_process(),

$classes_array $classes
<?php
function template_process(&$variables, $hook) {
// .
$variables['classes'] = implode(' ', $variables['classes_array']);

}
?>

298

16.

16.1 16.3
Drupal, . ,
.
, ,
. , , .

. , ,
. ,
,
.



. 16.4.
16.4.

<?php

/**
* template_preprocess_THEMEHOOK().

*/
function HOOK_preprocess_THEMEHOOK(&$variables) {
// .

}
/**
* template_process_THEMEHOOK().

*/
function HOOK_process_THEMEHOOK(&$variables) {
// .

}
:
1. , ,
template.
.
2. ? :
, , ,
.
3. hook_theme()
, .
4. &$variables ,
.
, .

,
hook_theme(). , hook_preprocess_node(),
hook_preprocess_node__article() . node__ article
.


16.5 ,
, , template__preprocess_node(),

299

node.tpl.php. node,
module hook_theme() node_theme(),
node.
16.5.


< ?php
function template_preprocess_node(&$variables) {
// .
// . http://api.drupal.org/api/function/template_preprocess_node/7.

}
function template_process_node(&$variables) {
// .
// . http://api.drupal.org/api/function/template_process_node/7.

, ,
http://api.drupal.org.


,
. ,
, .
,
. ,
, .
, ,
.
, Drupal ,
, modulename.module theme.inc .
, ,
template.php.

, dgd7. 16.6,
template.php, ( ),
_preprocess_n , node.
&$variables (
& $).
16.6. template_preprocess_node()

<?php

/**

\* template_process_node().

*/
function dgd7_preprocess_node(&$variables) {
// .

}
16.6 ,
Drupal
. , !

300

16.

$variables
$variables ; ,
,
.
, ,
, . ,
dpm().
16.7.
16.7.

<?php

/**

* template_preprocess_node().

*/

function dgd7_preprocess_node(&$variables) {
dpm($variables);


,
. ,
, ,
.

DGD7 http://definitivedrupal.org ,
, .
, .
template,
php, 16.8.
16.8. <div>. $classes_array

template_preprocess_region()
<?php

/**
* template_preprocess_region().
*/

function dgd7_preprocess_region(&$variables) {
$region = $variables['region'];
// .
// , #main #1-, ,
if (in_array($region, array('sidebar_first',
'sidebar_second', 'content'))) {
$variables['classes_array'][] = 'main';

// "clearfix" ,
if (in_array($region, array('footer', 'help', 'highlight'))) {
$variables['classes_array'][] = 'clearfix';

>

301

// "outer" ,
if (in_array($region, array('header', 'footer', 'sidebar_first',
'sidebar_second'))) {
$variables['classes_array'][] = 'outer';

>
}
{variables [ *classes_array' ] $class.
,
. <div> .
,
. .
,
. ,
. , 16.9.
16.9.

C S S-
/* ID, . */
#header fieldset,
#footer fieldset,
.sidebar fieldset {
border-color: #333

}
/* , 16.8, . */
.outer fieldset {
border-color: #333;

,
, html.tpl.php, block.tplphp, node.tpl.php comment,
tpl.php, .


16.10 :
1. page.tpl.php.
node.tpl.php, ,
<h2>. , ,
.
. 16.10 $title_ attrib u tes_
array.
2. ,
Add new comment . 16.10
hide(), .
3. , .
16.10 {v ariab les[ 't e a s e r ' ]
{submitted 70 .
16.10.

<?php

/**
* template_preprocess_node().

&

302

16.

16.10 ()

*/
function dgd7_preprocess_node(&$variables) {
// <h2>, .
$variables['title_attributes_array']['class'][] = 'node-title';
// "Add new comment",
if (!empty({variables['content']['comments']['comment_form'])) {
hide($variables['content']['links']['comment']);

>
// , ,
if ($variables['teaser']) {
// .
$variables['display_submitted'] = FALSE;
// .
$variables['title'] = truncate_utf8($variables['title'],
70, TRUE, TRUE);

}
>

, , , $variables .
. ,
user/UID/edit. {variables
, , , .
, ,
.
template_preprocess_user_picture(), 16.11.
user-picture.tpl.php,
16.12.
1 6 .1 1 . user-picture.tpl.php

template_preprocess_user_picture()
<?php

/**

* template_preprocess_user_picture().
* - "change picture" .

*/
function dgd7_preprocess_user_picture(&$vars) {
// ,
//
$vars['edit_picture'] = '';
// account ,
// . id user,
// ,
if ($vars['account']->uid == $vars['user']->uid) {
//
// "change-user-picture" CSS-.
$vars['edit_picture'] = 1('Change picture',
'user/' . $vars['account']->uid . '/edit',
array(
'fragment' => 'edit-picture',
'attributes' => array('class' => array('change-user-picture')),

)
);
}
}

Render API

303

16.12. user-picture.tpl.php,


<?php if ($user_picture): ?>
<div class="user-picture">
<?php print $user_picture; ?>

<?php print $edit_picture; ?>


</div>
<?php endif; ?>

Render API

,
render(). (render arrays)
,
, Drupal HTML-
(Render API).
renderQ.
page.tpl.php, ,
. ( ),
$page. 16.13 ,
. renderQ
HTML- .
16.13. page.tpl.php renderQ

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

Drupal <?php print $sidebar_


f i r s t; ?>, HTML. .
Drupal 7
. HTML-
, . ,

.
, dpm() Devel.
page.tpl.php: <?php dpm($page[' sidebar_f irst' ]); ?>.
. 16.4,
Search form Navigation, .
,..{.5)

rch Jbcm {, 26 a/aments)

systMnjruwiQation {Array,

11

{Boolean) TRUE

#thm*jMrapprs {Array, 1 atement)

0(String,characters} rQton

#r* >on (String,13characters)


Called from / U t a r s / j a c i n / S i t s / 4 r u p a l - 7 / m > d u l s / s y s t m / p o g e . t p l . php, lino 119

Krumo v m ie n 0.2.1a |

. 16.4. $page['sidebar_first], .

tpl.php dpm()

304

16.


. ,
. . 16.4, , $page[ sid eb ar_
f i r s t ' ] , #sorted, #theme_wrappers
# re g io n . d ru p a l_ re n d e r()
.
http://api.drupal.0rg/api/functi0n/render/7 .
,
,
. . 16.1.
1 6 .1 . ,

#theme

,

, () ,
. ,
#theme , #theme_wrappers
. ,

.
hook_element_info()
, (prefix) (suffix)

,
(TRUE FALSE), ,
. #weight
.
hook_page_alter(), #sorted => FALSE
#weight.
,

CSS-, JavaScript-

#theme_wrappers

#type
# prefix #suffix
#weight
#sorted

#attached

http://api.drupal.
org/api/function/drupal_render/7.


, ,
HTML-. ,
, .

. ,
, . ,
. ,
Render API:
1. .
2. .
3. .

Render API

305


, (alter hooks).
,
. HTML-,
. #theme,
,
. ,
.
, ,
.
,
.

.
16.14 new_stuff
Highlighted, hook_page_alter() template.php.
16.14. Highlighted
<?php

/**
* hook_page_alter().

*/

function mytheme_page_alter(&$page) {
$page['highlighted']['new_stuff'] = array(
'#type' => 'container',
'#attributes' => array('class' => 'my-container'),

)J

$page['highlighted']['new_stuff']['heading'] = array(
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => t('Heading'),
*#attributes' => array('id' => 'my-heading'),

>;

$page['highlighted']['new_stuff*]['list'] = array(
'#theme' => 'item_list',
'#items' => array(
'First item',
'Second item',
'Third item',

b
);
}
new_stuff, #type
c la ss m y-co ntain er. , co n tainei
, s y s te m _ e le m e n t_ in fo ()
th e m e _ c o n ta in e r( ).
(heading l i s t ) th e m e _ c o n ta in e r( ).
16.15.
c o n ta in e r,

16.15. , theme_container()
$page[,highlighted,][,new_stuff]
<div class="my-container">
</div>

306

16.

heading
#type html_tag.
theme_html_tag(). #tag, #value
#attributes. themejrtml_tag().
http://api.drupal.org/api/function/theme_htmLtag/7.
16.16.
16.16. , theme_html_tag()

$page[highlighted][*new_stuff][heading]
<h2 id=,,my-heading">Heading</h2>

list.
item_list #theme ,
#items theme_item_list().

16.17.
16.17. , theme_item_list()

$page[highlighted,][,new_stuff][,list]
<div class="item-list">
<ul>
<li class="first">First item</li>
<li>Second item</li>
<li class="last>Third item</li>
</ul>
</div>

Highlighted 16.14
, 16.18.
16.18. 16.14

<div class="my-container">
<h2 id="my-heading">Heading</h2>
<div class="item-list,,>
<ul>
<li class="first">First item</li>
<li>Second item</li>
<li class="last">Third item</li>

</ul>
</div>
</div>

, Render API .
, HTML-
, .
#type , ,
html tag, theme_html_tag().

hook_page_alter()
. 16.19 ,
, .
, .

Render API

307

16.19. sidebar_first sidebar_second



<?php
* h o o k_ p a g e _a lte r().

*/
fu n c tio n dgd7__page_alter(&$page) {
/ / , ,
i f (node_is_page(m enu_get_object())) {
/ / s id e b a r _ firs t sidebar_second.
$page['sidebar_second'] = $page[' s id e b a r _ fir s t' ] ;
/ / s id e b a r _ fir s t .
u n s e t($ p a g e ['s id e b a r _ firs t'] ) ;

>
/ / .
$ p a g e ['fo o te r '] [ 'breadcrum bs'] = a rra y (
'# ty p e ' => 'c o n ta in e r ',
'# a tt r ib u t e s ' => a r r a y ( ' c la s s ' => a rra y ( 'breadcrumb-wrapper' ,
' c le a r f ix ') ) ,
'#w eigh t' => 10,

);

$ p a g e ['fo o t e r '] [ ' breadcrumbs' ] [ ' breadcrumb'] = a rra y (


'#theme' => 'breadcrum b',
'#breadcrumb' => drupal_get_breadcrumb() ,

);

/ / .
$ p a g e ['fo o te r' ] [ '# s o r te d '] = FALSE;


,
, . ,
. , ,
.
16.20 View Edit Profile
Edit profile .
16.20. hook_

menu_local_tasks_alter()

<?php
/**

* hook_menu_local_tasks_alter() .
*/
function dgd7_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'user/%') {
/ / 'View' 'Profile',

if ($data['tabs'][0]['output'][0]['#link']['title'] == t('View')) {
$data['tabs'][0]['output'][0]['#link']['title'] = t('Profile');

'Edit' 'Edit p ro file ',


if ( S d a ta t 'ta b s 'n o n 'o u tp u t 'n i n 'tl in k 'n 't it l e '] == t('E d it')) {

/ /

$data['tabs'][0]['output'][1]['#link']['title'] = t('Edit profile');

}
>
>

308

16.


, ,
. hook_page_alter()
.
,
.
. ,
, , 16.2. , , ,
,
.
16.2.

$
page.tpl.php
$content

$tabs

$action_
links
$item

hook_page_alter()



node.tpl.php,
hook_node_view_alter(),
.
comment.tpl.
hook_comment_view_alter(),
php, taxonomy- hook_taxonomy_term_view_ http://api.drupal.
term.tpl.php
alter()
org/hook_entity_view_alter
page.tpl.php
hook_menu_local_tasks_al
ter()
,
theme_menu_local_tasks() theme_menu_local_task()
page.tpl.php
hook_menu_local_tasks_al .
ter()

theme_menu_local_actions()
field.tpl.php
hook_field_display_alter()

hook field display ENTITY
,
TYPE alter()

field.tpl.php

render(), hide() show()


, Drupal 7 ,
. ,
( )
HTML-, .
,
. Drupal .
{content, ,
, .
,
. ,

.
Drupal 7 .
render(), hide() show()
, .
.
, ( ).

render(), hide() nshow()

309

hide (). ,
drupal_render() , . :
<?php hide({element['something']); ?>

show(). hide().
. :
<?php show($element['something']); ?>

render( ). HTML-.
HTML-, print .
:
<?php print render({element); ?>

node.tpl.php ( 16.21).
1 6 .2 1 . node.tpl.php

<div id="node-<?php print {node->nid; ?>" class="<?php print {classes; ?>


clearfix"<?php print {attributes; ?>>
<?php print {user_picture; ?>
<?php print render({title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print {title_attributes; ?>><a href="<?php print {node_url; ?>"><?php
print {title; ?></ax/h2>
<?php endif; ?>
<?php print render({title_suffix); ?>
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print {submitted; ?>
</div>
<?php endif; ?>
<div class-"content"<?php print $content_attributes; ?>>
<?php
/ / .

hide($content['comments']);
hide($content['links']);
print render($content);

?>
</div>
<?php print render($content['links']); ?>
<?php print render($content['comments']); ?>
</div>

, render ()
hide(). : $title_prefix, $title_suffix
{content. <div class="content"> {content [' links' ]
{content [' comments' ] hide()
{content.
,
{content <div class="content">.
render().
, .
.
(. Render API).
, Add new comment ,
.
, (),
16.22.

310

16.

16.22. Add new comment

<?php
// "Add new comment",
// ,
if (!empty($vars[ 'content' ][ 'comments' ][ 'comment_form' ])) {
hide($vars['content']['links']['comment']);

// ,
print render($content['links']);

show( ) , ,
, hide().
, , render (),
, 16.23.
16.23. Add new comment


<?php
// "Add new comment",
// ,
if (!empty($content['comments']['comment_form'])) {
hide($content['links']['comment']);
if ($some_exception) {
show($content['links']['comment']);

}
}

// ,
print render($content['links'])j

.
,
.



. Drupal
(Form API).
.
, , ,
.
, Drupal .
Drupal , ,
.
. ,
? ,
, .


. ,
16.24. , . ,
,

311

,
.
$form .
1 6 .2 4 .
<?php
function exampleform_unsubscribe(&$form, $form_state) {
$form[email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address'),
'#required' => TRUE,

);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Remove me!'),

)J

return $form;

}
, :
Submit.
. 16.5. 16.25.
E-mail address *

Remove me!

. 1 6 .5 . , 16.24
1 6.25. , exampleform_unsubscribe()
16.24
<form action="/example/unsubscribe method^'post" id="exampleform-unsubscribe"
acceptcharset="UTF-8">
<div>
<div class="form-item form-type-textfield form-item-email">
<label for="edit-email">E-mail address
<span class="form-required" title="This field is required.">*</span>
</label>
<input type="text" id="edit-email" name="email" value="" size="60"
maxlength="128" class="form-text required />
</div>
<input type="submit" id="edit-submit" name="op" value="Remove me!" class="formsubmit" />
<input type="hidden" name="form_build_id" value="form-jKkllKLWDLnv0hM4DSVd840boTgBQAzWWhUn44cl5Q" />
<input type="hidden" name="form_token" value="LB07DqsDXK9idWdOHLxUen7jKxm52JqTyH
iR7-pNumA"/>
<input type="hidden" name="form_id" value="exampleform_unsubscribe" />
</div>

</form>

exampleform_unsubscribe() :
. #type
textf ield, .

312

16.

submit, <input
type="submit"/>.
16.25 ,
,
. , Drupal .
form, te x tfie ld submit,
system_element_info(), 16.26.
Drupal , .
16.26. , system_elementJnfo()

Textfield Submit
<?php
$types['form'] = array(
'#method' => 'post',
'taction' => request_uri(),
'#theme_wrappers' => array('form'),

);

$types['textfield'] = array(
'#input' => TRUE,
'#size' => 60,
'#maxlength' => 128,
'#autocomplete_path' => FALSE,
'#process' => array('ajax__process_form'),
'#theme' => 'textfield',
'#theme_wrappers' => array('form_element'),

);

$types['submit'] = array(
*#input' => TRUE,
'#name' => 'op',
'#button_type' => 'submit',
'#executes_submit_callback' => TRUE,
'#limit_validation_errors' => FALSE,
'#process' => array('ajax_process_form'),
'#theme_wrappers' => array('button'),

);

Drupal .
, , ,
http://api.drupal.Org/api/file/developer/topics/forms_api_reference.html/7.


, .
#theme #theme_wrappers.
Drupal, .
#pre_render ,
.
#theme. , .
#theme_wrappers. ,
.
$form[ email' ] :
1. :
theme('textfield', array('element' => $form['email']))

313

:
<input type="text" id="edit-email" name="email" value="" size="60"
maxlength="128" class="form-text required" />

2. :
theme('forn^element' , array('element => $form['email']))

:
<div class="form-item form-type-textfield form-item-email">
<label for="edit-email">E-mail address
<span class="form-required" title="This field is required.">*</span>
</label>
<input type="text" id="edit-email" name="email" value="" size="60"
maxlength="128" class="form-text required" />
<!-- RESULT OF THE RENDERED TEXTFIELD -->
</div>

3.
through theme_form(), #theme_wrappers .
, form_build_id, formjtoken
form_id, theme_form().

, theme_
. #theme #theme_wrappers
theme_.

.

, .
:
form_id,
:
<input type="hidden" name="form_id" value="exampleform_unsubscribe" />

-
,
ID <form>:
<form id="exampleform-unsubscribe">

,
Drupal-.
exampleform, unsubscribe.

. , , .module
. , .
.inc.
hook_theme()

, .
Drupal ,

314

16.

, , , ,
.
template.php hook_theme(),
hook . , Contact
/contact, contact_site_form.

, 16.27.
, , ,
. ,
.
16.27. hook_theme(), contact_site_form()


<?php

/**
* hook_theme().

*/

function THEMENAME_theme() {
return array(
// ID .
'contact_site_form => array(
// , 'form' -
'render element' => 'form',

h
);
}
,
, .

, ,
, . ,
, , http://api.drupal.org/api /fu n ction /
drupal_common_theme/7.


, ,
. ,
, .
, hook_theme()
index, 16.28.
hook_contact_site_form(), , .
theme_contact_site_form() ,
, : THEMENAME_contact_site_form().
16.28.

<?php

/**
* hook_theme().

*/
function dgd7_theme() {
return array(
'contact_site_form' => array(

315

'render element' => 'form',

),
)i
}
/**
* theme_forms_contact_site_form().

*/
function dgd7__contact_site_form($variables) {
// .
return drupal_render_children($variables['form']);

}
drupal_render_children()
drupal_render__children()
. , .
16.28 , ,
drupal__render_children($variables[ 'form' ]).
, render() ,
, Drupal ,
.
drupal_render_children($form). $form[ 'foo' ],
drupal_render() , .
, .

, . ,
, .
, .
16.29:
1. name mail.
2. name mail.
3. {output.
4. drupal_render_children({form) {output
.
5. {output.
1 6.29. theme_contact_site_form()

<?php

/**

* theme_contact_site_form().

*/
function dgd7_contact_site_form({variables) {
// subject. .
hide({variables['form']['subject']);
// "name" "mail".
{variables['form']['name']['#title'] = t('Name');
{variables['form']['mail']['#title'] = t('E-mail');
// output.
{output = '<div class="something">';
{output .= '<p class="note">'. t("We'd love hear from you. Expect to hear back from
us in 1-2 business days.") .'</p>';
{output .= render({variables['form']['name']);

&

316

16.

16.29 ()

$output .= render($variables['form']['mail']);
$output .= '</div>';
11
11 .
$output .= drupal_render_children($variables['form']);
I / output,
return $output;

}
. ,
hide(), show() render(). hide()
.
. .
, :
#weight, .
, message :
$variables['form']['message'][#weight] = -10;
$variables['form']['message'][#sorted] = FALSE;

, # d e s c rip tio n :
$variables['form']['mail']['tdescription'] = t(
"We won't share your e-mail with anyone.");

, . ,
Send yourself , #checked TRUE:
$variables['form']['']['#checked'] = TRUE;
#theme_wrappers, <div>

:
unset($variables['form']['mail']['#theme_wrappers]);

,
theme_table().
... . .!

,
.
.


,
. , template.php
hook_them e().
, 16.30:
path, :
template, .tpl.php.

.
, Drupal . ,
, .

317

16.30. hook_theme()

<?php

/**

hook_theme().

*/

function mytheme_theme() {
return array(
'contact_site_form' => array(
'render element' => 'form',
'path' => drupal_get__path('theme', 'mytheme') . '/templates',
'template' => 'contact-site-form',

h
);
}
hook_theme(), 16.30,
. templates,
: sites/all/themes/mytheme/templates/contact-site-form.tpl.php.
, , Drupal .
, ,
. :
<?php print drupal_render_children($form); ?>.

. ,
, , ,
,
drupal_render_children( ).

,
. 16.31
:
name mail;
name mail;
;
drupal_render_children ($form).
1 6 .3 1 . contact-site-form.tpl.php

<?php // "name" "mail".


$form['name']['#title'] = t(Name');
$form['mail']['#title'] = t('E-mail');

?>
<?php // "name" "mail" . ?>
<div class="name-and-email">
<px?php print t("We'd love hear from you. Expect to hear back from us in 1-2
business days.") ?></p>
<?php print render($form['name']); ?>
<?php print render($form['mail']); ?>
</div>
<?php // . ?>
<?php print drupal_render_children($form)j ?>

( -). ,
, .

318

16.

. name
{variables[ 'form' ][ 'name' ].
$form[' name' ]. ,
Drupal-.

, . Drupal
. Drupal
. #access
hook_form_alter().
21.



. ,
, , ,
IF. , ,
.
:
;
;
.
, .
,
, , . 16.32
.
16.32.

<?php

/**

hook_preprocess_contact_site_form().
V
function mytheme_preprocess_contact_site_form(&{variables) {
// form .
{form = {variables['form'];
// 'mail' 'name'.
{form['name']['#title'] = t('Name');
{form['mail']['#title'] = t('E-mail');
// .
{variables['note'] = t("We'd love hear from you. Expect to hear back from us in 1-2
business days.");
// .
{variables['name'] = render({form['name']);
{variables['email'] = render({form['mail']);
{variablesf'subject'] = render({form['subject']);
{variablesf'message'] = render({form['message']);
{variables['copy'] = render({form['copy']);
// .
{variables[children'] = drupal_render_children({form);

319

,
16.33 .
, . ,
.
16.33.


< class=Hnote"x?php print $note; ?></>
<pxspan class="form-required">*</span> <?php print t("Denotes required fields."); ?></
P>
<ol>
<lix?php print $name; ?></li>
<lix?php print $email; ?x/li>
<lix?php print $subject; ?x/li>
<lix?php print (message; ?x/li>
<lix?php print $copy; ?x/li>
</ol>
<?php print (children; ?>


Drupal 7.
, ,
,
hook_form_alter(), ,
,
.
:
, ;
#weight;
<div> <fieldset>;
;
.
, .
hook_theme().
. , ,
, .
:
hook_form_alter() ;
hook_f orm__FORM ID_alter () .
, hook_form_
a lte r () hook_form_FO#M_/>_alter(), ,
.
( 16.34),
hook_form_FO/?M_ZD_alter (), 16.35.
16.34. hook_form_alter()

<?php

/**
hook_form_alter().

*/
function mytheme_form_alter(&$form, &$form_state, $form_id) {
// .

&

320

16.

16.34 ()

if (!empty($form['title']) && $form['title']['#type'] == 'textfield') {


$form['title']['#size'] = 40;

}
}
16.35. hook_form_FORM_ID_alter()

<?php

/**

hook_form_FORM_ID_alter().

*/
function mytheme_form_contact_site_form_alter(&$form, &$form_state) {
// #markup .
$form['note']['#markup'] = t("We'd love hear from you. Expect to hear back from us in
1-2 business days.");
$form['note']['#weight'] = -1;
// 'mail' 'name'.
$form['name']['#title'] = t('Name');
$form['mail']['#title'] = t('E-mail');
// subject value .
$form['subject']['#type'] = 'hidden';
$form['subject']['#value'] = t('Contact Form Submission');

>

CSS-
Drupal . . !
CSS-, Drupal ,
. Drupal ,
CSS- JavaScript-. JavaScript-
, .
, :
, ;
Drupal , ;
Drupal .
Drupal,
. , .
- , .
, .
. , ,
.


, Drupal .
,
. Drupal .
10 40 CSS-. , ,
. Performance admin/config/
development/performance CSS- JavaScript. Drupal ,

CSS-

321

.
Internet Explorer, -
31. Drupal : -,
, ,
,
, . CSS-
. , CSS- JavaScript Drupal
, .
CSS- , .

, CSS-.

CSS- @import.
, ,
, .


CSS- .
css, . ,
layout.css, style,
css. , Zen, , 30 .
CSS- .
.
, Drupal.
CSS-
, ,
module-name.css. CSS-
,
. CSS- ,
.
, System, modules/system,
CSS-, , ,
. . 16.3,
, .
16.3. C S S - System, RTL

system, base,css

CSS-, JavaScript
,
,
,


HTML Drupal
,
,

system.theme.css
system.menus.css

&

322

16.

16.3 ()

system, messages, css

,
,


Drupal
,
,

system.admin.css
system, maintenance,css


, Drupal ,
.
(left-to-right, LTR), , ,
(right-to-left, RTL).
dir <html>
User Agent, CSS ,
, .
Drupal RTL-
CSS-. style.css
LTR- , style-rtl.css,
RTL-. Drupal
,
. RTL- LTR, .
CSS- , LTR-, RTL-,
CSS- LTR-, ,
. , Drupal
CSS-. 16.36.
16.36. CS S- LTR RTL-
// style.css:
// .my-selector , LTR,
// .
.my-selector {
border: solid lpx #ccc;
float: left; /* LTR */

// style-rtl.css:
// RTL- .my-selector
// , .
.my-selector {
float: right;

>

, CSS-
CSS- Drupal-.
, .
.info
CSS- .info ( 16.37 16.38).
:
, .info, ;

CSS-

323

d ru p a l_ a d d _ c s s ( ). ,
Internet Explorer
CSS- .info.
16.37. .info
s ty le s h e e ts [CSS media t y p e ][ ] = p a t h /t o /f ile .c s s

16.38. .info
s t y le s h e e t s [ a ll] [ ] = c s s /la y o u t. css
s t y le s h e e t s [ a ll] [ ] = c s s /s ty le .c s s
s ty le s h e e ts [ p r in t][] = c s s /p rin t.c s s

.info . ,
, theme. , -
AJAX- .
hook_css_alter(). , , .

drupal_add_css()
d ru p a l_ a d d _ c s s () CSS-
- . template.php,
.
d ru p a l_ ad d _ cs s( )
.
, CSS-, .
template.php tem p late _p re p ro c es s_h tm l( ),
16.39.
16.39. ,
<?php
fu n c tio n mytheme_preprocess_html(&$variables) {
/ / , ,
i f ( $ v a r ia b le s [ 'is _ f r o n t ' ] ) {
drupal_add_css(path_to_them e() . ' /css/hom epage.css',
a r ra y ('w e ig h t' => CSS_THEME));

}
}
CSS-
d ru p a l_ a d d _ c s s ( ), :
(inline) CSS- <head>
CSS-;
, , ,
CSS_SYSTEM (), CSS_DEFAULT ( ), CSS_THEME ();
;
,
;
CSS-;
CSS- .
Internet Explorer
, 43 %
Internet Explorer. ,
Internet Explorer.

324

16.

CSS- ,
.
Drupal 7 drupal_add_css().
Drupal template_preprocess_html().
template.php drupal_add_css()
.info. 16.40 16.41
Seven.
16.40. Seven, drupal_add_css()

template_preprocess_html() IE
<?php
function seven_preprocess_html(&$vars) {
// CSS- IE8 .
drupal_add_css(path_to_theme() . '/ie.css', ('grloup' =>
CSS_THEMEj 'browsers' => array('IE' => 'lte IE 8', '!IE' =>
FALSE)j 'preprocess' => FALSE));
// CSS- IE6.
drupal_add_css(path_to_theme() . '/ie6.cssarray('group' =>
CSS_THEME, 'browsers' => array('IE' => 'It IE 7', '!IE' =>
FALSE), 'preprocess' => FALSE));

}
1 6 .4 1 . , IE

<!--[if lte IE 8]>


<link type="text/css" rel="stylesheet" href="http://drupal-7/themes/seven/
ie.css?140z2j" media="all" />
<![endif]-->
<!--[if It IE 7]>
<link type="text/css" rel="stylesheet" href="http://drupal-7/themes/seven/ie6.
css?140z2j" media="all" />
<![endif]-->

16.40 16.41 ,
Internet Explorer. Internet Explorer 8 ,
IE7.

hook_css_alter()

Drupal CSS- drupal_add_


css(). template_process_html()
{styles, HTML-
. , 16.42,
<head> html.tpl.php.
16.42. $styles, template_process_html()

html.tpl.php
< ?php

/**
* template_process_hmtl().

*/
function template_process_html(&$variables) {
$variables['styles'] = drupal_get_css();

CSS-

325

drupal_get_css() Drupal CSS


d rupal_alter(' c s s ', $css). ,
/zoo_css_alter (), hook
.
CSS-.
, hook_css_alter(), ,
Locale. ,
RTL- CSS-, .
Aoo&_css_alter()
CSS-, .
template.php Seven ( 16.43). vertical-tabs.css,
, .
16.43. hook_css_alter() Seven

<?php

/**
* hook_css_alter().

*/

function seven_css_alter(&$css) {
// Seven
// ,
if (isset($css['misc/vertical-tabs.css'])) {
$css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme',
'seven') . '/verticaltabs. css';

>

// jQuery UI ,
if (isset($css['misc/ui/jquery.ui.theme.css'])) {
$css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme',
'seven') . '/jquery.ui.theme.css';

}
}

CSS- .info (
CSS-) . .info
, , .
hook_css_alter(),
, .


, CSS- .
.
. .info
1. css sites/all/themes/mytheme. ,
, .
2. css style.css print.css.
3. sites/all/themes/mytheme/mytheme.info ,
Drupal, :
stylesheets[all][] = css/style.css
stylesheets[print][] = css/print.css

326

16.

4. admin/config/development/performance. ,
.
. IE drupal_add_css()
1. css ie.css.
2. theme template.php, .
, <?php.
3. template_preprocess_html ()
IE drupal_add_css():
<?php

/**
* template_preprocess_html().

*/
function mytheme_preprocess_html(&$vars) {
// Internet Explorer 8 .
drupal_add_css(path_to_theme() . /css/ie.css', array('weight' =>
CSS_THEME, 'browsers' => array('IE' => 'lte IE 8', '!IE' =>
FALSE), 'preprocess' => FALSE));

}
.
drupal_add_css()
$is_f ront , ,
. ,
homepage.css. ,
.
<?php
// , ,
if ($variables['is_front']) {
drupal_add_css(path_to_theme() . '/css/homepage.css', array('weight' =>
CSS_THEME));

}
. CSS-
hook_css_alter()
hook_css_alter() template.php
mytheme_css_alter(). $css
, . ,
, node.css.
<?php
function mythemename_css_alter(&$css) {
// node.css.
if (isset($css['modules/node.css'])) {
unset($css['modules/node.css']);

}
}


, .
.
.

327

, Drupal
.
(subthemes) .
.
, . ,
.
, .


,
Drupal-. .
.
1. . .info,
.
2. .info base theme, ,
, :
base theme = basethemename

3. / , .info,
.
Drupal
. admin/
appearance. ,
.

.
, Zen, Omega Fusion, starterkit starter,
.
README.txt .

, Drupal ,
, API-.
.
.
. , , CSS JavaScript-, template.php.
CSS- JavaScript-, , ,
.
.
, ,
.
.
, . ,
.
.info .
. 16.4.

328

16.

16.4.

CSS-
JavaScript-


http://drupal.org/project/Themes . ,
Drupal , .
, ,
. drupal.org
, ,
, .
. ,
.
. drupal.org ,
. http://drupal.org/project/themes,
.
,
, , .
, .
. Maintenance
Development status, .
, .
Actively maintained Under active development, ,

, .
. Project Information
, View usage statistics,

. ,
.
, , .
. ,
.
,
. ,

.

drupal.org .
http://drupal.org/node/323993.
Drupal 7 :

329

Zen (http://drupal.org/project/zen);
Fusion (http://drupal.org/project/fusion);
AdaptiveTheme (http://drupal.org/project/adaptivetheme);
Genesis (http://drupal.org/project/genesis);
Basic (http://drupal.org/project/basic);
Blueprint (http://drupal.org/project/blueprint);
NineSixty (http://drupal.org/project/ninesixty);
Omega (http://drupal.org/project/omega);
Mothership (http://drupal.org/project/mothership).


.
. .
, , ,
. , .
. , .
' , , .
.
. ,
. , , CSS
, ,
.
CSS-. CSS-
, ,
. .


Drupal . ,
.
.
, .
,
Drupal.
. . ,
, , .


,
, . ,
, node.tpl.php, viewsview.tpl.php block.tpl.php, .
-, , -, ,
. Drupal
, ,
, .
block.tpl.php ( 16.44).
Block modules/block/block.tpl.php.

330

16.

, , .
, , JavaScript-,
, , .
16.44. block.tpl.php

<div id="<?php print {block_html_id; ?>" class="<?php print {classes; ?>"<?php print
{attributes; ?>>
<?php print render({title_prefix); ?>
<?php if ({block->subject): ?>
<h2<?php print {title_attributes; ?>><?php print {block->subject ?></h2>
<?php endif;?>
<?php print render({title_suffix); ?>
<div class="content"<?php print {content_attributes; ?>>
<?php print {content; ?>
</div>
</div>

Bartik block.tpl.php, Drupal .


block.tpl.php .

, ,
16.44 , 16.45.
16.45. block.tpl.php

<div id="block-block-l" class="block block-block first last odd">


<h2>Block title</h2>
<div class="content">
<p>Block content.</p>
</div>
</div>

.
.
CSS-.
,
block.tpl.php. .
:
. CSS-.
.block.
.
.
.
.block, ?
. block,
.content.
,
Drupal. ,
,
. ,
.
.
,
.

331

, . 16.46,
<div class=" inner" >,
.
<div class="inner">. . block,
.inner, .
16.46. block.tpl.php

<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print
$attributes; ?>>
<div class="inner">
<?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
<h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
<?php endif;?>
<?php print render($title_suffix); ?>
<div class="content"<?php print $content_attributes; ?>>
<?php print $content; ?>
</div>
</div>
</div>


Drupal
. .
,
.
.
- .
, Drupal .
.
: - ,
Drupal .
Drupal.
<div class="inner">, 16.46,
. ,
, :
.
.
. ,
nodearticle.tpl.php,
theme_links_node().
CSS- . ,
. ,
<h2>. CSS-,
<div class="content">. ,
.

CSS-
CSS-. .
-

332

16.

Drupal CSS-, .
( body)
, ,
<div>. ,
CSS.
, ,
, ,
.
CSS-,
system.base.css. , ,
, . ,

. ,
.


Drupal .
Drupal 7
.
, . Drupal
:
SQL-? . .
?
?
? ,
.
, ,
.

,
Drupal . ,
, , :
;
;
;
, ;
CSS- JavaScript- ;
.
, .
, .
, , Drupal-.

V.

17, 18 19
. , ,
.
20 Drupal 6
Drupal 7, .
21 ,
,
, ,
.
, .
22 ,
.
23 API
,
Drupal.

17.

, , Drupal ,
,
.
,
? . .
, Drupal ,
. ,
.
. (
) . , , . ,
, .
, 18
19 . :
, , , Drupal
;
, ,
Drupal.


,
. 18
;
, X-ray.
.


, :
, (, ).
.info,
.module. ,
(machine name):
.
, . -
, , xray.info xray.module, 17.1 17.2,
. .
17.1. xray.info

name = X-ray
description = ,
core = 7.x
17.2. xray.module ( /** */)

<?php

/**

* 335

* @file
* .

*/
/**
* hook_form_alter() .
V
function xray_form_alter(&$form, &$form_state, $form_id) {
$form[,xray_display_form_id'] = array(
'#type' => 'item',
'#title' => t('Form ID'),
'#markup' => $form_id,
'#weight' => -100,

);
, ! ,
. ,
:
, Drupal , .
sites/all/modules/custom ( custom,
).
X-ray ,
Modules (admin/modules). (,
Drush,
, Modules.) -
.
, (. 17.1);
, ,
system_modules ( ) .
Home * Administration

Modules

l is t

update

-A u

4> Install new module


Form ID

system_modules
CORE
ENABLED

NAME

A ggregator

VERSION

DESCRIPTION

7.0-dev

Aggregates
syndicated
content (R5S,
RDF, and Atom
feeds).

OPERATIONS

. 1 7 .1 . system_modules
( , )

, ,
, .
, Drupal .
Drupal, .

336

17.

,
. , . 19
, ,
.

, .
! ,
? , .


,
, Drupal . , ,
Drupal.org. ?
, sites,
Drupal .
sites/all/modules/custom,
.

, 30,
. , example_profile,
profiles/example__profile/modules.

, Drupal.org, sites/all/modutes/contrib.
, , Drush, 4.
sites/all/modules/contrib Drush
, Drupal.org.
sites/all/modules/custom
sites/default/modules, sites/
all/modules. .
Drupal
, sites.
Drupal ,
, Aegir (aegirproject.org), .
INSTALL.txt,
Drupal.
. 17.1.

Drupal ,
. sites/all/modules, ,
John Albin Wilkins Bad Judgment sites/all/modules/contrib/experiments/
set a/johnalbin/amusements/badjudgment, . ,
, .
Module, . Drupal
project, ,
.

337

1 7 .1 .

sites/all/modules/custom/
sites/exampie.com/mod ules/custom/
sites/default/modules/

,

example.com

Drupal

X-ray , Drupal
.
. ,
(sandbox).
.


Drupal. , 12.
. ,
,
SSH FTP.


, .
, modules,
, xray.info,
.
mkdir, , cd,
. vi,
, dgd7.org/vi.
- ,
,
, Linux
. (
!)
,
, - . ,
. , :
,
. Linux
Terminal, Mac OS X Terminal.app.

(, Mac OS X Finder Microsoft Windows Explorer),
( 17.3).
.
17.3. , modules

mkdir - sites/default/modules/xray
cd sites/default/modules/xray

338

17.


.
. 2 , Git, 14
.
, ,
.
, .
( ;
~/code/dgd7/web/sites/all/modules/custom/xray) Git. :
it init

, ,
.
.


. , ,
,
git add .
git commit -m "Basic xray.info and .module files."

14 (Karoly Negyesi),
Drupal,
. , , .

.

.info
Drupal ,
. .info : , Drupal, -
. Drupal .info,
. , ,
(admin/modules), .info. (
Help, Permissions Configure.)
.info
.info .
,
drupal.org/node/542202.
.info, machine_name.info:
name =
description = - , ,
core = 7.x

, ,
. .
( ), , ,
. , core
, 7. .

339

Drupal 7 $Id$.
CVS, Drupal.org, , ,
cvs.drupal.org, $Id$,
, . , Git, ,
Git , .


. ,
.info. ,
. core 7.x,
Drupal 7 . Drupal
Drupal, ,
. , , .


dependencies[ ], ,
. , Views,
.info :
dependencies[] = views

. , Views
CTools, CTools
.
() . ,
, ,
, .
?
[], .
, Help, Views,
dependencies [] , 17.4.

Drupal 7 ,
dependencies[] = ,
.
17.4. .info ,

; Help Views,
dependencies[] = help
dependencies[] = views
. .info
(;) . Drupal .
.info .
,
Help Views. (, .
, Views Bulk Operations vbo.)

: ,
>=. 3 .

340

17.

, .
dependencies [] = views (>=3.) Views 7.-3.0
( 4.x, ),
Views 7.-2.9. ,
. , ,
(ch x):
dependencies [] = foo (>=2., <4.17, !=3.7).
, foo 2- ,
4.17, .
3.7, , .
,
d e p e n d e n c ie s [], Drupal.
Drupal 7.0, , Drupal 7.1,
, ( ,
) 7.1 , :
dependencies[] = system (> = 7 .1 )

configure
c o n fig u re ,
, . Drupal

, .
c o n fig u re search:
configure = ad m in /c o n fig /se arch /s ettin g s

( .info X-ray , ,
.)

configure ,
.

package
package
(admin/modules). ,
, .
Other. - ,
package.


package. drupal.org/node/542202#package groups.drupal.org/
node/97054. , , .

X-ray Development, ,
. .info
,
. (
Vim dgd7.org/vi.) 17.5 ,
.info X-ray, package

341

Development. ( , dependencies [ ] ,
name description, .)
17.5. xray.info package

name = X-ray
description = Shows internal structures and connections of the web site,
package = Development
core = 7.x

, .info, Drupal ,
, ,
. Drupal;
... .

.info , ,
- , .info
, , Information added by drupal.
org packaging script. , drupal.
org/node/542202.

.module
, .module, , . ,
; .info! (,
.)
.module .info ,
. ,
, .
, ,
.
.
X-ray , .
.module. .module
, PHP-, <?php.
,
, , ,
<?php. PH P- .
.module, ,
, .
docblock, PH P-,
Drupal . ,
.

, //, ,
xray_form_alter (). ,
, ,
//. X-ray
, .
.module .
. @file ,

342

17.

( 17.6). .module
.info.
17.6. docblock

/**
* @file
* .

*/
/**
* hook_form_alter() .

*/

function xray_form_alter(&$form, &$form_state, $form__id) {


11 , .

}
/* */ ,
/* */. . Drupal
. 17.6
@file.
, Drupal ,
:
(/**); ,
( * ); ( */).
docblock
.
, .
, .
.
.
, xray_f orm_alter() hook_form_alter(). ,
? , .

,
Drupal . Drupal
( ,
, . .),
.
- . api.drupal.org/hooks,
Drupal 251 .
hook .
.
Drupal ,
.
, hook .
hook_form_alter() X-ray xray_form_alter().

hook_anything_whatsoever() (
.api.php, modules/system/system.api.php).
hook. , ,
, hook
.

343

Drupal
, , ,
. module_invoke_all() (
) , Drupal,
. , ,
:
module_invoke_al 1(' comment_view' $commentj $view_mode., $langcode);

hook_comment_view(). comment
, . ,
(view mode) (language code), ,
^ .
, .
api.drupal.org. , hook_comment_view() api.
drupal.org/hook_comment_view. API- ,
- , , .
(Larry Garfield) , ,
PH P-,
. , , ,
.
, Drupal, (
crell) garfieldtech.com/blog/language-tradeoffs. ,
, Drupal.

, Drupal
, . Drupal-
(Chacha Sikes). api.drupal.
org, , .

, Drupal, api.drupal.org,
drupalcontrib.org.
Drupal,
, API (drupal.org/project/api)
.
.api.php .
Drupal
X-ray help
h ook_h elp ( ). .
module , Structure
(admin/structure):
<?php
// [ ]...

/.**

* hook_help().

*/

function xray_help($path, $arg) {


if ($path == 'admin/structure') {
return t('This site has stuff!');

}
>

344

17.

This site has stuff! Structure


. Drupal , ,
. , ,
, , ,
. - , Drupal .
Drupal : hook_menu()
Drupal , -.
Structure (admin/structure),
Drupal, .
,
.
hook_menu() menu_router. (
27.)
,
,
.
( HTML,
Structure), Drupal .
.
, .
. Drupal,
,
.
, , ,
.
Drupal : hook_block__view()
system_help ( help)
Drupal hook_block_view().
, ,
Drupal .
, (system), (block_view).

. , system_block_view() hook_
block_view(). ( ,
; , Drupal 8, . drupal.
org/node/1114032.)

system hook_block_view() system_help,


Drupal help. system_block_view()
switch, .
"help", switch ( )
system_help. ,
, menu_get_active_help().
Drupal : hook_help()
, , Drupal , hook__help().
menu_get_active_help() Drupal
. : ,

345

, help.
hook_help() Drupal .
system_help. , help.
xray_help() ,
hook_help(). ,
. Drupal
.

, , Drupal
module_invoke_all(,x'), '' hook. ,
module_invoke_all(), .

hook_help() , (
, ),
$path, . h oo k_help ()
api.drupal.org/hook_help, Drupal modules/
help/help. api. php.

, , api.drupal.
org. , hook menu,
(api.drupal.org/api/search/7/hook_menu).
Drupal
API: api.drupal.org/hook_menu. , .
api.drupal.org Drupal 5, Drupal 6 Drupal 7.


Structure menu_get_active_help()
$path admin/structure hook_help() .
block_help() Block Drupal,
. node_help() Node
.
taxonomy_help() Taxonomy
, hook_help(). , ;
, Drupal
, admin/structure
,
. menu_get_active_help() xray_help()
X-ray, - admin/structure,
function xray_help($path, $arg) {
if ($path == 'admin/structure') {
return t('This site has stuff!');

}
}
xray_help() $path admin/structure
This site has stuff! menu_get_active_
help(), system_block_view().
, ,
Block, . , Drupal
, .

346

17.

$path
$arg 19, ,
hook_help().

X-ray ,
. Zebra zebra_help() ,
, .
hook_help().
, , , ,
, .
, xray_help()
, $path
admin/structure , , .
Drupal : hook_block_view_alter()
hook_block_BLOCK_ID_view_alter()

Block system_block_view()
. drupal_alter(),
hook_block_view__alter()
( system_help).
Drupal ;
hook__block_view_system_help_alter () ,
system_help. .
. .
Drupal.

. -
xray_block_view_system_help_alter() help,
. ,
. , Drupal
. ,
Drupal. ,

, .

Drupal

, , , Drupal
.
. Drupal .
, .

.
. (
.) Drupal
. , ,
!

. ,
, 12 dgd7.org/ide.

347


Drupal,
. , . ,
- .


, Drupal,
SQL. , , .
(Hypertext Preprocessor )
Drupal. -.
SQL (Structured Query Language )
, Drupal
.
SQL , Drupal
. ,
.
, SQL 18 , .

. ,
.
. ,
,
Drupal.
, Drupal. ,
,
php.net, , Drupal, api.drupal.
. (, , Drupal,
.)

, , php.net

. ,
URL- . , substr() php.
net/substr. ,
. php.net , ,
See also,
. ,
.

, ,
, . , ,
, .
(string) .
, .
, , .
.
(empty string).

348

17.

(integer) ,
. Z = {,.., -2, -1,0,1,2,...}
(php.net/integer).

(array)
(, , ) . Drupal
(nested arrays).
(associative array) (keys),
.
(object) Drupal , ,
(, $user $node).
,
, ,
.
(variable)
. , ,
$_. , ,
, , ,
(floats).
(function) , .
( ) .
,
, ,
.
. xray_form_alter()
xray_help().
(parameters), (arguments),
.
.

, .
, .
, . ,
example_takes_arguments, example_takes_
arguments($text = ' Hi . ' ) { . . . }, $text (
), ' Hi.'.


,
.

(assignment operator).
-
.
$num = 5;
$_ = (
'a_number' => $num,
*a_letter' => 'k',

);

349

$another_array = (
'a_letter' => "If merged this will overwrite k with a sentence. Oops.",
)}
$function_result = array_merge($an_array, $another_array);

(=).
.
, $function_result
:
array('a_number' => 5, 'a_letter' => If merged this will overwrite k with a sentence.
Oops.",


,
Drupal . :
$end = " completion of string";
$msg = "Start of string" . $end;

, ,
. :
$msg .= "!!!";

$msg :
Start of string completion of string!!!



, :
5 + 2 7;
5 - 2 3;
5 * 2 10;
5 / 2 2,5;
5 % 2 1.

, . :
5 == 2 FALSE ( ,

, ), a "apple" == "apple"
TRUE;
5 ! = 2 TRUE ( );
5 < 2 FALSE ( );
5 > 2 TRUE ( );
5 <= 2 FALSE ( ), 3 <= 3 TRUE;
5 >= 2 TRUE ( ), 3 >= 3 TRUE.

=== !==.
(identity comparison),

, . , FALSE
,
(, , ,
).
. :

350

17.

FALSE, 1 === 1 TRUE;


'' !== () TRUE.

1 === true


Drupal (ternary
operator), .
.
$resulting_value = ($condition) ? "If TRUE value" : "If FALSE value";

( , ).
. ,
. ,
($maybe__seven == 7). TRUE,
, .
, . (
.) php.net/ternary.

, ,
, Sresult = ($value) ? $value: "default".
,
, , .
Drupal 8. Drupal 7 5.2,
5.3. $value ?: "default"
$value, ,
FALSE. .
5.3, , ,
, .info php = 5.3.


Drupal :
$ && $ TRUE, $, $;
$ || $ TRUE, $ $;
!$ TRUE, $ TRUE.
&& 11 and
. ( ,
, $ $ TRUE,
.)

php.net/operator.


(control structures) ,
. ,
($ == $), ($ === $), ($ < $),
($ >= $) . . .

if, elseif else


if ,
else, , ,

351

if, FALSE. i f
e lse if. else,
, TRUE.
17.7.
17.7. if/else

if ($advice == 'good') {
$do = 'Follow it.';
}
elseif ($advice == 'bad') {
$do = 'Don\'t follow it.';
}
else {
$do = 'Who knows? If all else fails, do as you please.';
}

Dont follow it.


(\), .
,
.

i f () .
, ;
TRUE,
"== TRUE". :
if ($condition) {
// ,
take_exampLe_action();
}

,
. :
if (!$condition} {
// , .
take__example_action();
}

switch case
, switch, case.
if, elseif, elseif, elseif...,
. ,
.
, i f
($path == ' adm in/structure')... path
( 17.8 ). i f
switch/case. ( .
.)
17.8. xray_help() switch

switch ($path) {
case 'admin/content':
return _xray_help_admin_content();
case 'admin/structure':

&

352

17.

17.8 ()

return _xray_help_admin_structure();
case 'admin/appearance':
return _xray_help_admin_appearance();
case 'admin/people':
return _xray_help_admin_people();
case 'admin/modules':
return _xray_help_admin_modules();
}

switch ($path == ' admin/content')


case. , ,
case 'admin/content'. case.
php.net/switch.

, Drupal,
(loops). while ({expression) { ... } ,
{expression TRUE. ,
.
. while
php.net/while. for ($i = 0; $i < 5; $i++) {... }
, $i
; php.net/for. ,
foreach (Jarray as $key => $value) { . . . } ,
.
,
foreach ($lumps as $lump) {
$variables['extra'] .= krumo_ob($lump);
}

Drupal
: , ?
,
, . ,
. , . Drupal
.
;
.
,
. .

, ,
. .
drupal.org/coding-standards.
<?php

, <?php. ( <?php)
-.

353

PH P-.
(.module), (.inc), (.install), settings.php template,
php ( ) <?php, .

,
. :
Warning: Cannot modify header information - headers already sent by (output started at
/var/www/example/drupal/sites/default/oops/oops.module.php:37) in /var/www/example/
drupal/includes/bootstrap.inc on line 568.

, PH P-,
, .
, : (.tpl.php),
. HTML-,
PHP-, HTML.
PHP- , . (?>)
.

, , _f unction_name()
.
.
. , ,
.
. API-
, , , ,
( , 1.x 2.x). -,
Drupal- ( ,
250).


, __1().
- .
.

, , if,
,
, . (
,
; . 12 dgd7.org/ide.)
, , ;
if ,
.

else if
:

354

17.

if ($following_coding_standards) {
drupal_set_message("Good job!");
}
else {
drupal_set_message("Follow this examplel");
}

, (
) .
if. ,
. :
if ($following_coding_standards) {

foreach, while . .

, :
function space_standard($parameter, $another_parameter, $last_parameter) {
_space_standard($parameter, $another_parameterj $last_parameter);
}
, .

. , == >=,
, + /, , . . =,
, && | | , , = += (
,
. = ).
: - ,
.
. ,
,
if ($budget < $money || ($is_broke && !$has_credit)) {
$message = 'Your remaining $' . $money - $budget . ' is not enough.';
}

, .
, . (budget)
, (money), (is_broke)
(has_credit), (message) ,
('Your remaining $ ),
money budget (' is not enough.').
. -,
. $has_credit
: if $has_credit ,
!$has_credit . -,
, . , ,
. , ,
&& $is_broke !$has_credit,
,

355

. 11 ,
, .

(Stella Power), (Doug Green)
(Jim Berry) .
19.
Coder Review ( Coder drupal.org/project/
coder) , Drupal
.
(minor), (normal) (critical). ,
19, ,
.
Grammar Parser Solotandem (drupal.org/project/grammar_parser)
. ,
- , ,
Coder Review, ,
Grammar Parser .

JavaScript. . drupal.org/node/172169.

: - ,

Drupal ,
, , ,
,
.
, , Drupal
.
.
Configuration Performance Development
admin/config/development/performance.
Clear all caches. Shortcuts
, Admin menu,
.
drupal_
flush_all_caches(), index.php
drupal_bootstrap() menu_execute_active_handler(). .
, , , Drush drush all ( ,
, . dgd7.org/162).

, , ,
.

26 , .
. , Drupal , hook_menu() hook_theme(),
.

356

17.

: - ,

, , ,
, , Shift,
, , .
, . ,
, ,
.
, , Permissions
(admin/people/permissions)
(user/[wi6/]/edit, [uid] .

- ,
, ,
.

: ,

.
17.9 settings.php,
. ( Drupal 6
; . randyfay.com/node/76.)
17.9. settings.php,

error_reporting(-1);
$conf['error^level'] = 2;
ini_set('display_errors, TRUE);
ini_set('display_startup_errors', TRUE);

PHP- (-1
). Drupal
(2 ERROR_REPORTING_DISPLAY_ALL,
settings.php). ,
(WSOD)
.

,
Drupal.
, ,
Drupal . ,
.

. 18.

dgd7.org/intromodule.

18.
API

Drupal
. API A pplication Programming
Interface ( ). API
.
API, Drupal X-ray,
17.
API Drupal,
.
Drupal 251 .
, . , , ,
, ,
. Drupal,
API.
, ,
Zoe N eill-St. Clair C ontributed M odule Ideas (groups.
drupal.org/contributed-module-ideas). ,
Drupal,
, Drupal . ,
, , , , .
.
Drupal.
. , :
;
( );
;
hook_menu ();
;
.


hook_form_alter().
, :
, , -
, , . : -, ,
hook_form_alter(), Drupal, -, ,
hook_form_FORM_ID_alter() .
, api.
drupal.org, api.drupal.org/hook_form_alter. ,
hoo k_fo rm _alter( ), ,
. , ?
, Drupal , ,

358

18. API

. ,
.
api.drupal.org/api/drupal/developer--topics-forms_api_reference.html/7. (
dgd7.org/forms.) ,
, .
.
hook_form_alter()
,
. , -
, .
, X-ray, 17,
.
, . xray.module 18.1 (
x ra y _ fo rm _ a lte r( ) ,
).
18.1. hook_form_alter() X-ray,

/**
* hook_form_alter().
*/
function xray_form_alter(&$form, &$form_state, $form_id) {
debug($form, $form_id, TRUE);
}

modulename_form_alter() modulename_form_FORM_ID_alter()
. , , drush all.
25.

debug() ,
(, ). , ,
- ( , ,
Devel). , , ,
, , , ,
.
( , ),
, :
exit('Show me a s ig n ');

Drupal 7 , , debug().
,
. ,
debug(). , debug($user, 'User object');
Suser, Drupal ,
, .

( ,
Search Block)
, , . ,

359

, 18.1
.
,
. #type
'markup' ( ,
#type , ).

7 #type 'markup'
#markup, $['__'] = array('#markup' => t('OopMa, .'));

Drupal ' item',


, , , # title #description.
,
18.2.
18.2. hook_form_alter(), ,

/**
* hook_form_alter().
*/
function xray_form_alter(&$form, &$form_state, $form__id) {
$form['xray_display_form_id'] = array(
'#type' => 'item',
'#title' => t('Form ID'),
'#markup' => $form_id,
'#the*ne_wrappers' => array('container_xray__form'),
'#attributes' => array('class' => array('xray')),
'#weight' => -100,
);
}

, #prefix
#suffix. #theme_wrappers
#attributes, '#prefix' => '<div class="xray"> #suffix' => </div>',
. (
X-ray drupalcode.org/project/xray.git/commit/839927e.)
30,
^themewrappers' => array(' container__xray__form') '#attributes' => array(class' =>
array('xray')). HTML-, ,
,
(, </div>). ,
, .
form container__xray__form
, , ,
. THEME_container__xray__form()
THEMEcontainer__() ( THEME ),
. THEME_container(). ,

, api.drupal.org/theme_container. ,
, .

#markup HTML,
, HTML.

360

18. API

$form_id -,
, .
HTML- . ,
,
$f orm_id .
Drupal $form_id HTML .
(-100) ,
.

Form API Drupal . ,



, Drupal Form API.
Node Block,
. .
node_form_block_admin_configure_alter() node.module
hook_form_FORM_ID_alter(), block admin configure
. Open ID
xyKaopenid_form_user_login_alter() openid_form_user_login_block_alter() (
user login user login block ).

t()
format_plural()
form _alter() t ( ) , ,
.
translate (), Drupal.
,
Drupal ( , , )
.
, .
t ().

( ,
) Drupal. ,
, ( ,
, , ),
. ,
. Drupal
,
il8n.
(localization internationalization) .
, , dgd7.org/translate.

,
, , ,
. ,
( ,
), . ,
.
X-ray t (' Content summary'). , ,

361

-;
, !
-, .
, . ,
,
. t ()
, ,
. ,
: @,
, %
, , ! ,
( ! ,
). api.drupal.org/t.
, %: %func
%func ( $page_callback
) <>:
$output = t('the function %func', array('%func' => $page_callback . '()'));

,
format_plural(). , t()
( 18.3).
18.3. format_plural()

$output .= format_plural(
xray_stats_content_type_total(),
'The site has one content type.',
'The site has gcount content types.'
);
format_plural() .

( ,
).
xray_stats_content_type_total(). ,
.
, ,
. @count ( ,
) ,
( t ()), .


, , . , , - , ,
, , ,
, .
(
, , ),
, .
, , , !
1. , .
2. .
3. , (
) .

362

18. API

, Drupal (. dgd7.
org/233).

,
( ).
, ,
Drupal, , .
, , ,
.
,
.
, ,
system. system.module 4000 .
, .
Drupal-,
. , Drupal.
Drupal
: Appearance,
admin/appearance, !
(. dgd7.org/ide) ,
. ,
. . -, ,
. -, , .
, Drupal- .
, Appearance (admin/appearance)
.
hook_menu(). .module. ,
Drupal,
, :
grep -nHR --include=*.module 'admin/appearance' modules

grep ,
:
modules/system/system.module:590: $items['admin/appearance'] = array(

.
, (modules/system/system.module)
(590). "$items" , (
hook_menu() ).
,
system.module ( 18.4).
18.4. admin/appearance 590 system.module
// Appearance.
$items['admin/appearance'] = array(
'title' => 'Appearance',
'description' => 'Select and configure your themes',
'page callback' => 'system_themes_page',
'access arguments' => array('administer themes'),
'position' => 'left',
'weight' => -6,
'file' => 'system.admin.inc',
>;

363

, .
, , ,
, . system.admin.inc.
, .module,
hook_menu().
, system.admin.inc system_themes_page().
. system_rebuild_theme_data()
.
. ,
. ? ,
! , ,
.
system_rebuild_theme_data() _system_rebuild_
theme_data() ( ,
,
). api.drupal.org/api/function/_system_
rebuild_theme_data/7. , .
system_rebuild_theme_data(),
list_them es(), system_rebuild_theme_data(),
. (
Drupal drupal.org/node/941980.)

list_themes() ;
, .
, , , list_themes() :
$list = &drupal_static(_FUNCTION__, arrayQ);


, list_them es(), ... .
X-ray , , ,

, .
Appearance,
, _system_rebuild_theme_data().
list_themes().
PH P-, Drupal .
, , , debug()
, 18.5.
18.5. !ist_themes() debug()
-
/**
* hook_help().
*/
function xray_help($path, $arg) {
switch ($path) {
/ / ...
case 'admin/appearance':
return _xray_help_admin_appearance();
// ...
>

&

364

18. API

18.5 ()
/**
* admin/appearance.
*/
function _xray_help_admin_appearance() {
debug(list_themes());
}
:
debug(list_themes());
hook_help(),
, - Appearance ( admin/appearance).
_xray_help_admin_appearance() ,
, .
,

dgd7.org/145. Drupal
( 18.6).
18.6. Bartik,
list_themes() ()
array (
'bartik' =>
stdClass::_set_state(array(
'filename' => 'themes/bartik/bartik.info',
'name' => 'bartik',
'type' => 'theme',
'owner' => 'themes/engines/phptemplate/phptemplate.engine',
'status' => '1',
'bootstrap' => '0',
'schema_version' => '-1',
'weight' => '0',
'info' =>
array (
'name' => 'Bartik',
'description' => 'A flexible, recolorable theme with many regions.',
'package' => 'Core',
'version' => '7.0-dev',
'core' => '7.x',
'engine' => 'phptemplate',
'stylesheets' =>
array (
'all' =>
array (
'css/layout.css' => 'themes/bartik/css/layout.css',
'css/style.css' => 'themes/bartik/css/style.css',
'css/colors.css' => 'themes/bartik/css/colors.css',
b
'print' =>
array (
'css/print.css' => 'themes/bartik/css/print.css',
b
b
'regions' =>
array (
'header' => 'Header',
'help' => 'Help',

365

'page_top' => 'Page top',


'page_bottom' => Page bottom,
'highlighted' => Highlighted',
featured => 'Featured',
content => Content,
sidebar_first' => 'Sidebar first',
'sidebar_second => Sidebar second,
triptych_first => Triptych first,
'triptych_middle' => Triptych middle,
triptych_last => 'Triptych last',
'footer_firstcolumn' => 'Footer first column,
footer_secondcolumn => Footer second column,
'footer_thirdcolumn' => Footer third column,
footer_fourthcolumn => 'Footer fourth column',
footer => 'Footer',
'dashboardjnain' => 'Dashboard main',
dashboard_sidebar => 'Dashboard sidebar',
b
'settings =>
array (
'shortcut_module_link' => 0 ,

features =>
array (
0 => logo,
1 => favicon,
2 => name,
3 => slogan,
4 => node_user_picture',
5 => "comment_user_j>icture,
6 => comment_user_verification,
7 => mainjnenu,
8 => secondary_menu,
)>
screenshot' => themes/bartik/screenshot.png,
php => '5.2.5',
'scripts' =>
array (
'overlay_regions' =>
array (
0 => 'dashboard_main',
1 => 'dashboard_sidebar',
).
regions_hidden =>
array (
0 => page_top,
1 => page__bottom,

overlay_supplemental_regions =>
array (
0 => page_top,
b
)>
stylesheets =>
array (
all =>
array (

&

366

18. API

18.6 ()
'css/layout.css' => 'themes/bartik/css/layout.css',
'css/style.css' => 'themes/bartik/css/style.css',
'css/colors.css' => 'themes/bartik/css/colors.css',
b
'print' =>
array (
'css/print.css' => 'themes/bartik/css/print.css',
b
),
'engine' => 'phptemplate',
)),
II . . .
)
in xray_help_admin_appearance() (line 109 of
/home/ben/code/dgd7/web/sites/default/modules/xray/xray.module).

Garland, Seven, Stark Test,


Update test. , ;
: , TRUE.
( 18.7).
18.7.
/**
* .
*/
function xray_stats_enabled_themes() {
$themes = list_themes( );
.
$num_hidden = 0; // .
// , ,
foreach ($themes as $themename => $theme) {
// .
if (isset($theme->info['hidden']) && $theme->info['hidden']) {
$num_hidden++;
}
}
return compact('num_hidden');
}
/**
* admin/appearance.
*/
function _xray_help_admin_appearance() {
$output = '';
$data = xray_stats_enabled_themes();
$output .= format_plural(
$data['num_hidden'],
'There is one hidden theme.',
'There are @count hidden themes.'
);
return theme('xray_help', array('text' => $output))j
}
$num_hidden . foreach

, if
$num_hidden .
$num_hidden++ $num_hidden = $num__hidden
+ 1;. if , 'hidden'
TRUE. issetQ

367

, . ,
, ' hidden' .
if,
. , foreach.
, , .
'hidden ' is s e t() TRUE, i f
( &&) $theme->info[ 'hidden' ].
TRUE ( 1), if.

, &&, TRUE,
. FALSE,
,
&& TRUE .
||.
TRUE, . FALSE
, TRUE ,
.

compact() (
) . ' num_hidden' (
$num_hidden), ,
, .
,
.
theme. Bartik 18.7,
status. ,
(1) (0).
info . , .
, , count(),
18.8. ( php.net/count.)
18.8.
/**
* .
*/
function xray_stats_enabled_themes() {
$themes = list_themes();
$num_themes = count($themes);
// .
$num_hidden = 0; // .
$num_enabled = 0;
$summaries = array()j
// , ,
foreach ($themes as $themename => $theme) {
// He , .
if (isset($theme->info['hidden']) && $theme->info['hidden']) {
$num_hidden++j
}
else { // ,
if ($theme->status) {
$num_enabled++;
// , .
$summaries[$theme->info['name']] = array(
'regions' => count($theme->info['regions']),

&

368

18. API

18.8 ()
'overlay_regions' => count($theme->info['overlay_regions']),
'regions_hidden' => count($theme->info['regions_hidden']),
'features' => count($theme->info['features']),
'kindsofstylesheets' => count($theme->info['stylesheets']),
'allstylesheets' => isset($theme->
info['stylesheets']['all']) ? count($theme->
info['stylesheets']['all']) : 0,
);
}
}
}
return compact('num_themes', 'num_hidden', 'num_enabled', 'summaries');
}

, , ;
foreach, ++ ( ,
), count ()
. isset()
' stylesheets' ' all',
. . ,
, dgd7.org/262!

,
,
. , . , -
, IRC.
, , ,
, , :
? system_rebuild_theme_data().
, ,
-, , . , ,
.
( X??),
. : X
Y Z. ?.

hook_menu()
, , ,
. ,
,
, , , Drupal.

Examples (drupal.org/project/examples), menu_example


api.drupal.org/hook_menu hook_menu(). 27
Drupal.

, Path
. , ,
. , Drupal ,
node/1883 1883? .
,

hook_menu()

369

megabetternodes/, ,
, megabetternode/rg. ;
Node API (api.drupal.org/api/group/node_api_hooks/7),
, .
, Drupal
(node/, user/, taxonomy/term/) hook_menu(),
.
. X-ray .
,
hook_help () .


? ,
Drupal,
.
, Drupal.org
.

Drupal ,
, Node Contact .
(, node/99 contact), (,
admin/content/node admin/structure/contact). User
user/3/edit user/register, Drupal 7
admin/people admin/config/people. ,
, .

, X-ray . ,
, ,
admin/.
hook_menu() admin/xray,
.
(admin/config) (admin/modules)!
Drupal
: Dashboard, Content, Structure, Appearance, People, Modules, Configuration, Reports
Help.
Structure Configuration - Configuration. -
. , ,
Reports. admin/reports/xray.


, , . Drupal- (
, .) hook_menu().

Drupal , ,
. hook_menu()
- , , ,
- . , AJAX-,
.

370

18. API

Drupal,
hook_menu(), , AP I Drupal.
api.drupal.org/hook_menu api.drupal.org/api/
function/hook_menu/7.
hook_menu() .module ,

,
Node Contact.
node.module,
Drupal- modules/node. hook_menu()
.
. Drupal , .
5-10 , ,
- . ,
18.9.
18.9. hook_menu() Node
/**
* hook_menu().
*/
function node_menu() {
$items['admin/content'] = array(
'title' => 'Content',
'description' => 'Find and manage content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_admin_content'),
'access arguments' => array('access content overview' ),
'weight' => -10,
'file' => 'node.admin.inc',
);
/ / ...
return $itemsj
}

Drupal- ,
, .

;
admin/content.
. ( Drupal
,
, .) ,
. , , ,
MENU_NORMAL_ITEM,
( ) .
.
admin Content
Drupal, hook_menu_alter()
Comment admin/content
.

hook_menu()

371

7
t(). ,
.
. ,
FALSE.
. t().

, . ,
, .
.
.
Drupal , .
.

Node file.
'file' => filename.extension Drupal .
, .module, .
,
. (
, ),
. Drupal
, admin/content node.admin.inc.
, (),
,
.

18.9
Node hook_menu().
, .
. ,
, ; admin/content admin/reports/xray.


, Node
, 18.10.
18.10. hook_menu() Node,

$items['admin/content/node'] = array(
'title' => 'Content
'type' => MENU_DEFAULT_L0CAL_TAS,
'weight' => -10,
);

, .
MENU_DEFAULT_LOCAL_TASK. type
, MENU_NORMAL_ITEM,
(). , ,
, . 18.1.

372

18. API

Home Administration

Content

CONTENT

. 18.1. () Content,
admin/content/node Node

.
, ,
admin/content admin/content/node
.
Overview -.
,
.

Drupal .
Drupal 8 (drupal.org/node/948416),
, MENU_LOCAL_TASK
MENU_DEEAULT_I^CAL_TASK.

-
, 18.11.
18.11. hook_menu() -
/**
* hook_menu().
*/
function xray_menu() {
$items['admin/reports/xray'] = array(
'title' => 'X-ray technical site overview',
'description' => 'See the internal structure of this site.',
'page callback' => 'xray_overview_page',
'access callback' => TRUE,
);
$items['admin/reports/xray/overview'] = array(
'title' => 'Overview',
'description' => "Technical overview of the site's internals.",
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
return $items;
}

menu router.
Drupal 6 (
), . , ,
menu_rebuild(), ,
hook_menu(). data.agaric.com/node/3376
, , ,
.
drush all (, drush menu).

373

, .
. ,
( )?
,
TRUE FALSE, .
user_access(), Drupal
,
. ,
TRUE. .
, .

.
access callback, access arguments, (
) , user 1,
.

, , admin/reports/xray
X-ray .
hook_permission()
.



Permissions (admin/people/permissions)
Drupal,
. Drupal
,
, , .
, , Drupal,
, ( ) 60 ,
. 18.2.

.
, , ,

.
Drupal : ,
. , ,
,
. , , ,
. , ,
. , , .

, ,
hook_menu_alter ().

hook_permission().
system.module api.drupal.org/
hookpermission.

374

18. API

Home * Administration * People

People

p e r m is s io n s
Rotes

Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role.
(See the Roses page to create a rote). Two important roles to consider are Authenticated Users and Administrators. Any
permissions granted to the Authenticated Users role will be given to any user who can tog into your site. You can make any role
the Administrator role for the site, meaning this will be granted all new permissions automatically. You can do this on the User
Settings page. You should be careful to ensure that only trusted users are given this access and level of control of your site.
Show descriptions
PERMISSION

ANONYMOUS USER

AUTHENTICATED USER

ADMINISTRATOR

Administer comments and comment settings

(5

View comments

Block

I Administer blocks
Comment

. 1 8 .2 . Permissions
Drupal ,

, ,
. . ,
admin/people/permissions, ,
. -,
, -, .
; ,
( user 1,
).

7 .
, , , ,
.

, ,
() . ,
X-ray.
.


(Moshe Weitzman), Drupal,
Drupal ( ,
).
Drupal. (
, 18.12,
phpMyAdmin) ,
role_permission.

375

18.12. SQL-
Drupal
mysql
mysql> SHOW DATABASES;
mysql> USE d7scratch;
mysql> SHOW TABLES;
mysql> SELECT * FROM role_permission WHERE rid=3;

SQL- 18.12 ,
, , , .
Shift CapsLk, ,
, .

, Drupal
. (Rid), 3, ,
( 18.13). ,
, . role_permission
, .
( ,
).
18.13. SELECT * FR O M role_permission W H E R E rid=3

Drupal
I rid || permission
|

3
3
3
3
3
3

3
3
3

3
3
3
3
3
3
3
3
3
3
3
3
3

j
|
|
|

|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
I

access administration pages


access comments
access content
access content overview
access contextual links
access dashboard
access overlay
access site in maintenance mode
access site reports
access toolbar
access user profiles
administer actions
administer blocks
administer comments
administer content types
administer filters
administer image styles
administer menu
administer modules
administer nodes
administer permissions
administer search
administer shortcuts
administer site configuration
administer software updates
administer taxonomy
administer themes
administer url aliases
administer users
block IP addresses

| module

|
|
|
j

|
|
|
|

system
comment
node
node
j contextual
| dashboard
| overlay
| system
| system
| toolbar
| user
| system
j block
| comment
| node
j filter
I image
| menu
j system
| node
j user
j search
| shortcut
| system
j system
| taxonomy
| system
I path
| user
j system

j
|
|
|
|
|
|
|

j
|
|

j
j
|
|
|

j
j
|
|

|
|

j
j
|
|

&

376

18. API

18.13 {)
| 3 bypass node access
| 3 cancel account
| 3 change own username
| 3 create article content
| 3 create page content
| 3 create url aliases
| 3 customize shortcut links
| 3 delete any article content
| 3 delete any page content
| 3 delete own article content
| 3 delete own page content
| 3 delete revisions
| 3 delete terms in 1
| 3 edit any article content
| 3 edit any page content
| 3 edit own article content
| 3 edit own comments
| 3 edit own page content
| 3 edit terms in 1
| 3 post comments
| 3 revert revisions
| 3 search content
| 3 select account cancellation method
| 3 skip comment approval
| 3 switch shortcut sets
| 3 use advanced search
| 3 use text format filtered_html
| 3 use text format full_html
| 3 view own unpublished content
1 3 view revisions
| 3 view the administration theme

+------

node
|
user
|
user
|
node
|
node
|
path
j
shortcut
|
node
j
node
j
node
|
node
|
node
|
taxonomy
|
node
j
node
|
node
|
comment
|
node
j
taxonomy
|
comment
j
node
|
search
|
user
|
comment
|
shortcut
|
search
|
filter
j
filter
j
node
|
node
|
system
j
i------------ +

61 rows in set (0.00 sec)


X-ray: access site reports ( ).
Reports (admin/reports).
-.

Drupal .
.


Drupal.
, ,
. Permissions
(admin/people/permissions) View site reports,
Drupal. 18.14 grep,
terminal. Drupal-
IDE.
Drupal grep view site reports
.module modules.

377

18.14. ( )

View site reports Drupal


grep -nHR --includes*.module 'View site reports' modules
modules/system/system.module:233: title' => t(View site reports'),

grep ( ) ,
233 system.module, 18.15.
18.15. hook_permission() System

/**
* hook_permission().

*/
function system_permission() {
return array(

// ...
'access site reports' => array(
'title' => t('View site reports'),

),
// ...
);
>

, .
23,
18.15: , hook_permission().

hook_permission() ,
,
( ).
View site reports ,
system_permission(), Access site reports.
, 18.16.
18.16. , Access site reports
$items['admin/reports/xray'] = array(
'title' => 'X-ray technical site overview,
'description' => 'See the internal structure of this site.',
'page callback => *xray__overview_page',
'access arguments' => array(access site reports),

);

, , (
).



, .
,
, 18.17.
18.17. , ( )

-
function xray_menu() {
$items = array();

&

378

18. API

18.17 ()

II . . .
$items['admin/reports/xray/permissions'] = array(
title' => 'Permissions'j
page callback => ,xray_permission_names_page',
'type' => MENU_LOCAL_TASK,
weight => 10,
'access arguments' => array(access site reports),
);
// ...
return {items;
}

10, Overview,
-10. ( ) ,
, , , , . ,
, ,
, . 18.3.
technical site overview
. 18.3.

, (MENU_DEFAULT_LOCAL_TASK),
, (MENU_LOCAL_TASK).
/ access callback
.


xray_permission_names_page()
, !


,
hook_permissions() .
? module_invoke_all(),
. ,
- :
$permissions = module_invoke_all('permission');

{permissions ,
, ,
.
:
// ,
foreach ({permissions as $machine_name => {permission) {
{names[$machine_name] = {permission['title'];
>

.
PHP.net ,
php.net/sort. -

379

sort(), ,
. , ,
, .
.
asort():
// .
asort($names);

Notes
See Also.
. , ,
, .
$names
, .




H T M L - . ,
D rupal , A PI,
. , .
, ,
.
, Permissions, admin/people/
permissions, ( ,
). ad m in /p eop le/p erm ission s ,
, modules/
user/user.admin.inc user_admin_permissions() theme_user_admin_permissions().
api.drupal.org/user_admin_permissions api.drupal.org/
theme_user_admin_permissions.
Doxygen
User. theme_user_admin_permissions()
18.18.
18.18. Doxygen theme_user_admin_permissions()
/**
* HTML- .
*

* ( $variables
* , :
*
- form: , .
*
* @ingroup themeable
*/
, $variables.
form,
,
docblock.

380

18. API

@ingroup them eable


User theme_user_admin_permissions()
@ingroup themeable docblock. @ingroup
.
,
. , ,
, . :
$output .= theme('table', ('header' => $header, 'rows' => $rows,
'attributes' => array('id' => 'permissions')));
$rows ,
. , ,
, ( )
H T M L -. api.drupal.org/
theme_table.
18.19 -,
, hook_permission().
18.19. ( , )
/**
* -.
*/
function xray_permission_names_page() {
$names = xray_permission_names();
return theme('xray_permission_names', array('names' => $names));
>
/**
* .
*/
function xray_permission_names() {
$names = arrayQ;
$permissions = module_invoke_all('permission');
// ,
foreach ($permissions as $machine_name => $permission) {
$names[$machine_name] = $permission['title'];
}
// .
asort($names);
return $names;
}
/**
* HTML- .
*
* @param $variables
* , :
*
- names: .
*
* @ingroup themeable
*/
function theme_xray_permission_names($variables) {
$names = $variables['names'];
$output = '';
$header = array(t('Permission title'), t('Permission machine name'));
$rows = array();
foreach ($names as $machine_name => $title) {

381

$rows[] = array($title, $machine_name);

}
$output .= theme(table', array('header' =>
$header, 'rows' => $rows, 'attributes' =>
array('id => 'xray-permission-names')));
return $output;

,
, ,
xray_permission_names ().
theme_xray_permission_names(),

Drupal. , .


,
I can be your module, you can be my theme (drupal.org/project/powerballad).
,
. theme (),
. Drupal
, .
theme () Drupal,
#theme #theme_wrapper.
.
hook_theme(),

.
theme_, _. 18.19 ,
xray_permission_names ,
( ,
). 18.20 hook_theme( )
X-ray, xray_permission_names
.
18.20. xray_permission_names

/**
* hook_theme().

*/
function xray_theme() {
return array(
'xrayjjermissioi^names' => array(
'render element' => 'names',

),
);
}

, ' xray__permission_names',
theme_xray_permission_names(),
, .
$variables, .
.

382

18. API

hook_theme()
. ,
. ,
drupal_flush_all_caches(). , , .
.
admin/config/development/performance Clear all caches.
, , drush all.


15, , , ,
. , ,
, Drupal.org.
hook_theme() api.drupal.org/hookJheme.
theme_ Drupal, ,
Drupal api.drupal.org/api/group/themeable/7.
Using the Theme Layer (Drupal 7.x)
drupal.org/node/933976.
Drupal groups.drupal.org/node/6355
, HTML-,
.

Drupal.org .
, Drupal 6,
7. ,
.


Drupal 7,
!

. , Drupal
, ,
.
, .
.
xray_permission_names_page(), ,
, , .
,
, 18.21.
18.21.
X-ray, Drupal 7

/**
.

* @return
* , drupal_render().

Drupal

383

*/
function xray_permission_names_page() {
$build = ();
// , .
$names = xray_permission_names();
// .
$header = array(t('Permission title'), t('Permission machine name'));
$rows = array j
foreach ($names as $machine_name => $title) {
$rows[] = array($title, $machine_name);
>
$build['names_table'] = array(
'#theme' => 'table_xray__permission__names',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'xray-permission-names')
);
return $build;
>

,
, theme_table(),
Drupal , #theme
. , , ,
, (#rows, #header,
#attributes), Drupal , .
, ? .
.
, !
, : table
table__xray__permission_names. ,
.
theme_table(),
( X-ray,
).
theme().
, , , ,
, .
hook_page_alter().

Drupal
Drupal-;
, . 18.22
( X-ray
Drupal),
Drupal- .
18.22. menu_get_item()
/**
* (
).
*/
function xray_show_page_callback() {

&

384

18. API

18.22 ()

// ; menu_get_item() ,
// $path,
// node/% node/1.
$router_item = menu_get_item();
// drush menu_get_item() null,
if ($router_item) {
return theme('xray_show_page_callback', $router_item);
}
}
/**
* .
*/
function theme_xray_show_page_callback($variables) {
extract($variables, EXTR_SKIP);
$output = '';
$output .= '<p class="xray-help xray-page-callback">';
$output .= t('This page is brought to you by ');
if ($page_arguments) {
foreach ($page_arguments as $key => $value) {
$page_arguments[$key] = drupal_placeholder($value);
}
$output .= format_plural(count($page_arguments),
'the argument !arg handed to ',
'the arguments !arg handed to ',
array('!arg' => xray_oxford_comma_list($page_arguments))
);
}
$output .= t('the function %func',
array('%func' => $page_callback . '()'));
if ($include_file) {
$output .= t(' and the included file %file',
array('%file' => $include_file));
}
$output .= '.</p>';
return $output;
>
$router_item , menu_
get_item(), . 18.22

, .
, .
, - xray_oxf ord_
comma_list(), .

, .
theme_
xray_show_page_callback() 18.22.
extract($variables, EXTR_SKIP);. Svariables
, ,
. ,
hook_theme(). EXTR_SKIP
, .

, theme_xray_show_page_callback() (
), , Drupal
, hook_theme() ( 18.23).

: CSS-

385

18.23. hook_theme(), xray_show_page_callback



/**
* hook_theme().
*/
function xray_theme() {
return array(
// [ ]
'xray_show_page_callback' => array(
'variables' => array(
'page_callback' => NULL,
'include__file' => NULL,
'page_arguments' => NULL,
b
b
);
}

He !
, {variables,
. , hook_theme() (
page__callback, include_f ile page_arguments),
,
. paBHbi^NULL,
. ,
, ,
, 18.23,
menu_get_item(). NULL
.
,
hook_help() ( dgd7.org/259).

: CSS-
, , ,
. ,
. Drupal !
(Cascading Style Sheets, CSS),
.info, ,
. CSS- ,
HTML- .
stylesheets [TYPE ][], TYPE
, (, . .).
- ,
. ,
all, 18.24.
18.24. .info Stylesheets
name = X-ray technical site map
description = Shows internal structures and connections of the web site,
package = Development
core = 7.x
stylesheets[all][] = xray.css

386

18. API

.info stylesheets, files.


1 8 .2 5 . CSS- - xray.css

p.xray-help,
div. {
display: block;
color: white;
padding: 5px;
background-color: black;
border: 4px solid white;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}

, .info 18.25, Drupal


CSS- ( xray.css). xray.info
xray.css ,
xray.info xray.css. 18.25

(. 18.4).
h o o k _ h e lp ()
h o o k _ fo rm _ a lte r().

This is brought to you by the function use*/ adivinO. vvhicii lives in the file
111 dt i/e s/t is e tA> er, admm. X ) .

The site has 2 a c t i v e u s e r s and one blocked user.


+ Add user

Form ID
user filter form ,

. 1 8 .4 . X-ray (
)

CSS- .
CSS-
CSS-. , Drupal
CSS- , - ,
.

, CSS- ,
HTML- ( , CSS- ),

API

387

HTML/CSS, Firebug Firefox,


. 18.26
xray.css.
Stark, Bartik Garland. ,
, Seven.
18.26. xray.css
/* . */
div.xray {
font-size: 0.923em;
>
/* - ( ID ). */
div.xray .form-item {
margin: 0;
padding: 0;
}

API
Drupal 7 ,
Data Objects (PDO), , .
DBTNG, Drupal 7
(Larry Garfield), .
- , SQL-.

,
SQL. :
,
, ;
;
;

.
,
Database API Drupal 7, Drupal-
( ).
,
. Drupal MariaDB/MySQL, PostgreSQL
SQLite. MSSQL (drupal.org/project/sqlsrv)
Oracle (drupal.org/project/oracle). NoSQL MongoDB,
Drupal, 26
Field API ,
, , SQL.

Drupal 7 . ,
, ,
, .
, api.drupal.org/db_transaction.
, (
, ).

388

18. API


( , )
.

( , ,
MariaDB/MySQL).
.
D B T N G
Drupal 7. , . ,
drupal.org/developing/api/
database api.drupal.org/api/group/database, Example (drupal.org/project/examples).

Select
, ,
Drupal, ,
.
, , X-ray
Structure,
. , .
node_type.
,
phpMyAdmin.
Drupal
( MariaDB/MySQL, Postgres SQLite). ,

(SQL). (
) ,
SQL . ( ,
Database API, ,
.)
SQL (
, , ). , SELECT,
db_query(), 18.27.
18.27. SQL- node_type
db_query("SELECT COUNT(*) FROM {node_type}")->fetchField();

SQL- . "SELECT
column_a, column_b FROM table_y".
node_type.
( ->fetchField()) db_query()
. 2 ( Article Basic)
Drupal.
db_query () ;
, .
Drupal ,
SQL-.

db_query() fetch*().

API

389


. WHERE.

phpMyAdmin mysql
. ( ) ( ).
( );
db_query() db_select() Drupal
. .
, , phpMyAdmin.

18.28 SQL, phpMyAdmin.


18.28. SQL-,
,
SELECT COUNT(*) FROM node_type WHERE disabled = 0;

SQL, , ,
=. SQL <>
.

Drupal, db_query ()
SQL- . 18.29
18.27 Drupal; ,
.
18.29. SQL-
node_type
db_query(SELECT COUNT(*) FROM {node_type} WHERE disabled = :status'\ array(status
=> 0))->fetchField();

node_type {node_type>;
, .
. disabled = 0 disabled = : status.
,
. , ,
, . disabled
= Jstatus; : disabled =
: status array( ' : status' => Jstatus).
.
,
, .
, string (
).

, , test.php,
index.php ,
. .
test.php 30 dgd7.org/testphp.

Drupal
db_select(), .

390

18. API

SQL, db_query().
, SQL
- Drupal .
, db_select(),
, 18.30. ,
Database API ( ).
18.30.
db_select('node_type')
->fields('node_type')
->condition('disabled', 0)
->countQuery()
->execute()
->fetchField();

node__type, ,
, WHERE disabled = 0, countQueryQ,
. countQuery()
, .
db_select()
see dgd7.org/235.

,
,
. , Drupal 7 Entity API,
( ). .

,
db_select(), , SQL db_query().


Join
, -
. modules/block.module ,
.
, API-,
. ,
. , 18.31.
.
18.31. ,

/**
* , .
*/
function xray_stats_blocks_enabled_by_theme() {
return db_query("SELECT theme, C0UNT(*) as num FROM {block}
WHERE status = 1 GROUP BY theme")->fetchAHKeyed();
}
->fetchAllKeyed(), Drupal
db_query (), ,

API

391

( ) ,
.
18.32. , db_query("SELECT theme, COUNT(*) as num
F R O M {block} W H E R E status = 1 G R O U P BYtheme")->fetchAIIKeyed();
array (
'bartik' => '10',
'garland' => '7',
'seven' => '9',
'stark' => '7',
)

->fetchAllKeyed()
.

18.32 . -, ,
Doin,
. -, ,
. ,
18.33.
18.33. Block System,

/**
* .
*/
function xray_stats_blocks_enabled_by_theme() {
return db_query("SELECT b.theme, COUNT(*) as num FROM {block} b INNER JOIN {system}
s ON b.theme = s.name WHERE s.status = 1 AND b.status = 1 GROUP BY b.theme")>fetchAHKeyed ();
}
b
{block} ( ).

.
join, - , , ;

. b where,
status = 1, b. status = 1.
status , system,
block, status.
system, , s,
join, from .
:
FROM {block} b INNER DOIN {system} s ON b.theme = s.name

join ,
. ON
, ; theme
block (b), , name system
(s), , .
, ,
system theme, block name.
theme b ,

392

18. API

s name.
, .

:

,
,
X-ray. 18.34,
, Structure
xray_stats_blocks_enabled_by_theme() ,
.
18.34. Structure
/**
* Structure (admin/structure).
*/
function xray_structure_summary() {
$data = array();
$data['blocks_enabled_by_theme'] = xray_stats_blocks_enabled_by_theme();
$data['block_total'] = xray_stats_block_total();
$data[,content_type_total'] = xray_stats_content_type_total();
// @TODO ,
return $dataj
}
/**
* hook_theme().
*/
function xray_theme() {
return array(
// [ ] ...
'xray_structure_summary' => array(
'variables' => array(
data' => arrayO,
'attributes' => array('class' => 'xray-help' ) t
),
),
);
}
/**
* hook_help().
*/
function xray_help($path, $arg) {
$help = ";
// [ ] ...
switch ($path) {
// .
// [ ] ...
case 'admin/structure':
$variables = array('data' => xray_structure_summary());
return $help . theme('xray_structure_summary', $variables);
// [ ] ...
default:
return $help;
}
}
/**

API

393

* HTML- Structure (admin/structure).


*
* gparam $attributes
* () HTML-,
* drupal_attributes().
* @param $variables
* ,
* - data: xray_structure_summary().
*
* @ingroup themeable
*/
function theme_xray_structure_summary($variables) {
// xray_structure_summary() ,
extract($variables[data'], EXTR_SKIP);
$attributes = drupal_attributes($variables['attributes']);
$output = '';
$output .= "<p $attributes>";
$output .= t('This site has (total blocks available. Of these,',
array('@total' => $block_total));
$output .= ' ',
$list = array();
foreach ($blocks_enabled_by_theme as $theme => $num) {
$item = '';
$item .= format_plural($num, '1 is enabled', '@count are enabled');
$item .= ' ' . t('on %theme', array('%theme' => $theme));
if ($theme == variable_get('default_theme', 'bartik')) {
$item .= t(', the default theme');
}
elseif ($theme == variable_get('adminjtheme', 'seven')) {
$item .= t(', the admin theme');
}
$list[] = $item;
}
$output .= xray_oxford_comma_list($list, array('comma' => '; '));
$output .= '. ';
$output .= format_plural($content_type_total,
'The site has one content type.',
'The site has @count content types.'
);
return $output;
}
xray_oxford_com m a_list() 19, ,
API Drupal.
, .
18.35. -
/**
* .
*/
function xray_overview_page() {
$build = ();
$build['intro'] = array(
'#markup' => '<p>' . t("Technical overview of the sites internals. These summaries
also appear / can be configured to appear on main administration section.") . </p>,
);
// .
// [ ] ...

$build[' structure_title' ] = array(

394

18. API

18.35 ()
'#theme' => 'html_tag',
#tag => 'h3',
'#attributes' => ('class' => 'xray-section-title'),
'#value' => t('Structure summary'),
);
$data = xray_structure_summary();
$build['structure_summary'] = array(
'#theme' => 'xray_structure_summary',
'#data' => $data,
'#attributes' => array(class' => 'xray-report'),
)j

return $build;
}

.
,
HTML- themeQ,
xray_overview_page()
, Drupal , .
, #theme
#data, .
CSS. ,
CSS, ( #attributes).
, ,
. SQL-.

variable_get()
,
(
db_query()) SQL-.
xray_stats_content_type_total(), ,
18.36. .
, ,
block. - ,
.
18.36. ,
/**
* Drupal.
*/
function xray_stats_block_total() {
11 . block ,
// ( ).
return db_query("SELECT COUNT(*) FROM {block} WHERE theme = :theme", array(:theme'
=> variable_get('theme_default', 'bartik')))->fetchField();
}

18.36 variable_get(). ,
( ' bartik')
, ,
variable_set(). , variable_set()
, - , .
{variable} ( $conf

API

395

) , variable_get()
.
,
(. dgd7.org/252).

Drupal . ,
, ,
.
(comment, block, variable),
users, user MySQL.


, SQL, ,
.
. Database API.
db_select()
db_query(). :
INSERT, UPDATE DELETE ( Database API
db_insert(), db_update() db_delete() );
SELECT, Drupal, , ;
SELECT, (
, db_query
);
SELECT, ,
, ,
db_select(), a ->condition()
LIKE ( NOT LIKE). ,
.

,
db_select() ->addTag('node_access')
->execute(). ,
,
. , ,
SQL, Database API,
, . ,
. db_query(),
.
( ).
, db_select() (
, Drupal). , ,
.

.
Drupal ;
API. ,

, .

396

18. API

, Drupal 7
.
.
, !
;
. ,
SQL, .

.install
, hook_schema().
, ,
.module, , .install.
hook_install(), hook_schema(), hook_uninstall() hook_update_N().
.install, hook_schema().
, . hook_install()
( ), ,
drupal_set_message() ,
.
hook_update_N(),
example_update_7000 example_update_7001(). ,
hook_schema() . ,
, hook_update_N(), ,
.
. install (, ,
) hook_requirements(),
,
hook_update_dependencies(), , hook_update_N(),
hook_update_N() , .

.install dgd7.org/253.

Drupal 7 , ,
hook_install() hook_uninstall(). .install
hook_schema(), Drupal ,
.
, hook_uninstall()
variable_del() SQL-
db_delete().


, .
-
. ,
, , , ,
. :
;
;

API

397

;
, .
, , module_implements_alter(),
,
.
, , .

,
, Drupal .

,
, : .
, , (
), .
, , ,
. X-ray

cache_bootstrap (. dgd7.org/255).


Drupal .install hook_schema()

. : varchar. ,
, int.
, system_schema()
info {system}, ,
, blob.
, int. (
),
(),
. .
, , .
.install, hook_schema().
X-ray 18.37,
.


.install, , Field API,
.
18.37. xray.install
<?php
/**
* @file
* , -.
*/
/**
* hook_schema().

&

398

18. API

18.37 ()

*/
function xray_schema() {
$schema['xray_hook'] = array(
'description* => 'A record of hook invocations (
using module__invoke_all).', 'fields' => array(
'hook' => array(
'description' => 'The primary identifier for a node.',
'type' => 'varchar',
'length' => 255,
'not null* => TRUE,
'default' => ",
h
'first' => array(
'description' => 'Timestamp of when the hook was first recorded.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
default' => 0,
b
'last' => array(
'description' => 'Timestamp of when the hook was last recorded.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
b
'count' => array(
'description' => 'Total count of times the hook is recorded as
invoked. Note that this is only recorded after a cache clear.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'modules' => array(
'description' => 'A serialized array of module machine names for
the modules which implement this hook.',
'type' => 'blob',
'not null' => TRUE,
),
'modules_count' => array(
'description' => 'Count of the number of implementing modules.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
b
),
'indexes' => array(
'xray_hook_first' => array('first'),
'xray__hook_last' => array('last'),
'xray_hook_count' => array('count'),
'primary key' => array('hook'),
);
return $schema;
}

API

399

, Drupal
,
. , ,
. ,
1.2, 1.3
, 1.4 . ,
1.4, hook_schema(),
. (
), 1.1 1.2, ,
. 1.3
, .
1.4. - -,
.
, .
hook_update_N() dgd7.org/261.


, .

. , ,
db_merge(). , , :

{xray_hook} db_insert() db_update().
db_merge()?
, ,
. , . ,
, , count .
SQL-. db_insert () db_update()
18.38. ,
DBTNG-, .
18.38. API- db_insert() db_update()
/**
* hook_module_implements_alter().
*/
function xray_module_implements_alter(&$implementations, $hook) {
// hook_module_implements_alter() -
// xray_hook,
// .
// ,
// ,
static Stable = NULL;
if ($table === FALSE || !($table = db_table_exists('xray_hook'))) {
return;
>
$is_existing = (bool) $count = db_query('SELECT count FROM {xray_hook}
WHERE hook = :hook V array(':hook' => Shook))->fetchField();
// 1 , .
// $count++ , $count FALSE,
if ($is_existing) {
$count++;

&

400

18. API

18.38 ()
else {
$count = 1;
}
//
// , .
$timestamp = time();

$ field s = array(
'la s t' => (in t) $timestamp,
'count' => (in t) $count,
'modules' => serialize($im plem entations),
'modules_count' => (in t) count($implementations),
);

i f ($is_existin g) {
/ / .
db_update('xray_hook')
- > field s($ fie ld s )
- >condition( 'hook', $hook)
->execute();
>

else {
/ / ,
$ field s['h o o k '] = (string) $hook;
$ fie ld s [ ' f i r s t '] = (in t) $timestamp;
db_insert('xrayjiook')
- > field s($ fie ld s )
->execute();
}
}

( ,
), db_merge().
db_update(), db_insert().
. api.drupal.org/db_merge drupal.org/node/310085.

.
debug( ) .
dgd7.org/256.


. . Recent log
messages Database logging .
, , , , .
Finding a Drupal function that Does What You Need ,
, X-ray : This page is brought to you by the function
dblog_overview() and the included file modules/dblog/dblog.admin.inc. (
dblog_overview() modules/dblog/dblog.admin.inc.)

dblog overviewQ modules/dblog/dblog.admin.


inc ,
.

401

. 18.5
,
. (
) ('#theme' => 'ta b le ').
, 'ta b le ', HTML-.
, ' #theme' => ' table__
hooks' 'tab le_'
'ta b le __hooks'. ( )
, theme_table() .
, ,
api.drupal.org/theme_table. ,
dblog.admin.inc.
! FIRST
j RECORDED

j LAST
j RECORDED

2011-04-03
08:21

2011-04-03
08:21

2011-04-03
08:21

2011-04-03
08:21

2011-04-03
07:12

2011-04-03
08:21

admtn^pathsafter

2011-04-03
07:12

2011-04-03
08:21

advancedhetotoplcinfoatter

2011-04-03
07:12

20114)4-03
07:12

block, book, comment, menu, menublock, node, search, shortcut, system,


user, and views

2011-04-03
08:21

2011-04-03
08:21

dashboard

2011-04-03
08:21

2011-04-03
08:21

IMPLEMENTING MODULES
actionjnfo

comment, node, system, and user

actionjnfoalter

adminjpaths

btockjnfo

: btock info after

block, book, node, openkl. shortcut, system, taxonomy, and user

. 18.5. ,

, module_implements()

18.39 db_query().
method ->extend( 'TableSort') ,
( ' h'), ,
theme_table() ,
.
( )
array_keys() . ,
Drupal xray_module_implements_alter(),
, , .
,
, FALSE. ,
; .
Drupal , .
Drupal .
,
( ) array_keys().
.

402

18. API

, !
, . Hooks,
X-ray ,
Reports, .
18.39. , {xray_hook}
HTML-
/**
* hook_menu().
*/
function xray_menu() {
// [ ] ...
$items['admin/reports/xray/hooks'] = array(
'title' => 'Hooks',
'page callback' => 'xray_hook_implementations_page',
type' => MENU_LOCAL_TASK,
'weight' => 20,
'access arguments' => array('access site reports'),
);
return $itemsj
>
/**
* , .
*/
function xray_hook_implementations_page() {
$build = array();
$header = array(
array('data' =>t('Hook'), 'field' => 'h.hook'),
array('data' => t('Implementing modules'),
'field' => 'h.modules_count'),
array('data' => t('First recorded'), 'field' => h.first'),
array('data' => t('Last recorded'), 'field' => h.last),
);
$rows = array();
$query = db_select('xray_hook',!h')->extend('TableSort');
$query->fields('h', array('hook', 'modules',
'modules_count', 'first', 'last'));
$result = $query
->orderByHeader($header)
->execute();
foreach ($result as $invocation) {
// ,
if (empty($invocation->modules)) {
$modules_text = t('<em>None</em>');
}
else {
$modules = array_keys(unserialize($invocation->modules));
$modules_text = xray_oxford_comma_list($modules);
}
$rows[] = array(
// . , $headers!
$invocation->hook,
$modules_text,
format_date($invocation->first, 'short'),
format_date($invocation->last, 'short'),
);
}
$build['hook_table'] = array(

403

'#theme' => 'table_xray_hooks',


'#header' => $header,
'trows' => $rows,
'#attributes' => array('id' => 'xray-hook-implementations'),
'#empty' => t('No hooks recorded yet (this is unlikely).'),
);
// , .
return $build;
}

, , !
, Recent log messages,
. HTML- ,
,
.
, .

, - , .
,
, - .

, Implementing modules
,
, . ,
, drupal.
org/node/109493. ?
drupal table sort different column . ,
?
. .
, , . ,
.


item_list() themeCitemJst', arrayCitems => $modules));,
- .
xray_oxford_comma_list(), .
HTML- CSS.

:
modules_number,
,
. .
,
modules, , $invocaton ,
, .
! ( .)
,
, ,
. , , ,
. .
. , , , .

404

18. API

. ,
.


Drupal 7 ,
. , , , ,
Drupal 7.
, hook_entity_inf ();
23.
,
Drupal. Drupal 7
, . ,
Drupal
. Drupal 6 Content Construction Kit (drupal.org/project/
cck)
(, , , ,
. .). . Drupal 7
( ),
,
. (bundle),
, , .

,
. , ,
, Drupal 7.


field_info_bundles (). ,
Structures, ,
debugQ. (, ;
. dgd7.org/ide.) test.php (dgd7.org/testphp), ,
hook_help(),

:
debug(field_info_bundles());

.
11 ,
( dgd7.org/151). ,
Drupal- .
, field_info_
bundles (), ,
. , , ,
. . ,
file file, comment
, .

. comment,
field_info_bundles(). ,
.

405

field_info_bundles()
-. dgd7.org/254
debug , ,
, .

(API)
.
Drupal,
, , ,
hook_menu(), .
.

API Drupal, ,
.
, , ,
19.
, , ,
Drupal.org.
.

- , dgd7.org/intromodule.
-.

19.

17 18 .
. , :
;
Drupal.org,
.

X-ray , ,
.
( , )
. ,
, ,
.
,
.
X-ray
,
. ,
.


Drupal Configuration,
, , , .
, , . Configuration D rupal 7
, ( ) People, Content authoring, Media, Search and metadata,
Regional and language, System, User interface, Development Web services. X-ray
,
Development (admin/config/development).
( )
,
.
,
. Drupal 7 ; ,
. , ,
X-ray, Reports;
, Configuration.
,
Drupal, ,
, ,
. h o o k _ h e lp ()
X-ray
.

407

Drupal,
, Drupal
( 19.1).
19.1. -

/**

* hookjnenuQ.

*/
function xray_menu() {
$items = ();

//

. . .

// .
$items['admin/config/development/xray'] = (
'title' => 'X-ray configuration',
'description' => 'Configure which elements of internal
site structure will be shown.',
'page callback' => 'drupal_get_form',
'page arguments' => array('xray_admin_settings'),
'file' => 'xray.admin.inc',
'access arguments' => array('administer site configuration'),
'weight' => 0,

);

return $items;

}

'page callback', 'page arguments' 'f i l e '.
, ' page callback' ,
Drupal . drupal_get_form()
. ,
,
hook_forms () ,
.
' page arguments'. ' f i l e ',
' xray_admin_settings', drupal_get_form(), _
admin_settings(). , , .

, (
), Drupal
.
, 'drupal get form',
. , ,
.

Drupal,
. User.
Account settings
user_menu() user.module. admin/config/people/accounts
X-ray :
This page is brought to you by the argument user_admin_settings handed to the function
drupal_get_form(), with the help of the file modules/user/user.admin.inc.

408

19.

( useradm insettings drupal_


get_form() modules/user/user.admin.inc.)


. -,
. -, Drupal
. ( ' file '
admin/config/development/xray. xray.admin.inc
.)
drupal_get_form(),
Drupal.
, . xray.admin.inc xray_admin_settings()
user.admin.inc user_admin_settings().

, .
User hook_menu() admin/config/people system_admin_
config_page(). ,
Configuration.
, X-ray Development (admin/config/development).


Form API .
system_settings_form(),
$f, ,
. , , ,
! , ,xray_display_section_summaries'
,
variable_get(). Drupal ,
, ! 19.2
, X-ray.
admin/config/development/xray.
1 9 .2 . ,

-
<?php

/**
* @file
* III -.

*/
/**
* ; , - .

* -.

* @ingroup forms
* @see system_settings_form()

*/
function xray_admin_settings() {
$form = a rra y ;

409

// -.
$form[display'] = array(
#type' => 'fieldset',
'#title' => t('Display options'),

);

$form['display']['xray_display_section_summaries'] = array(
'#type' => 'checkbox',
'#title' => t('Show summaries on administration sections.'),
'#default_value' => variable_get('xray_display_section_summaries', 1),
'#description' => t('If unchecked, the summaries will still be visible
on the <a href="@xray-overview">X-ray reports</a> page.',
array('@xray-overview' => url('admin/reports/xray'))

),
);

$form['display']['xray_display_callback_function'] = array(
'#type' => 'checkbox',
'#title' => t('Show the page callback function on all pages.'),
'#default_value' => variable_get('xray_display_callback_function', 1),

);

$form['display']['xray_display_form_id'] = array(
'#type' => 'checkbox',
'#title' => t('Show form ID in forms.'),
'#default_value' => variable_get('xray_display_form_id', 1),

);

return system_settings_form($form);

}
. 19.1,
.
DISPLAY OPTIONS
Show summaries on administration sections.

If unchecked, the summaries will still be visible on the X-ray reports page
V Show the page callback function on all pages.
& Show form ID in forms.

Save configuration

. 1 9 .1 .

Drupal : Drupal
. Drupal ( $conf,
variable_get()
). system_settings_form()
,
variable_set() . $conf
.
,
. , ,
, .
,
Drupal, .

410

19.

Drupal 8
; dgd7.org/config.
, Drupal 7.

- ,
. ,
,
, $conf.

: .
, -, ,
.
, , -
. ,
, , ,
13, - . ,
- , .
, , 'View -
messages'. admin/people/permissions ,
-. Administer site configuration', ,
, -
, . ,
'Administer site configuration' 'View X-ray output'
, Drupal
. , : 'Administer X-ray' 'View
X-ray output'. 19.3.
19.3. - hook_permission()

/**
* hook_permission().

*/
function xray_permission() {
return array(
'view xray messages' => array(
'title' => t('View X-ray messages'),
'description' => t('Allows users to see X-ray output.'),

'administer xray' => array(


'title' => t('Administer X-ray'),
'description' => t('Allows administrators to configure whichX-ray messages are shown.'),

b
);
}
admin/peopie/permissions,
.

, ,
, .
\.

411

xray_ m en u( ) ' a d m in is te r s i t e
' a d m in is te r x r a y ' , .
'V ie w X -ra y messages' ,
-.
c o n f ig u r a t io n '

Drupal- ,
.
- .

v a r ia b le _ g e t ( ). i f
, TRUE;
. ,
:
if

( v a r ia b le _ g e t( ' x ra y _ s h o w _ fo rm id ') ) { . . .


u s e r_ a c c e s s ( ). .
if , ,
( ,
, , ). , i f
,
( 19.4).
1 9 .4 .

fu n c tio n exam ple_som ething($account = NULL) {


i f ( !u s e r_ a c c e s s ('d o som ething co m p le x', $ a c c o u n t)) {
r e tu r n ;

}
/ / , ,
/ / 'do something co m p le x'.

}
, - ,
, .
. user_access ()
{a c c o u n t.

. ,
, . , , ,
,
. 19.4. $ c o u n t
NULL, , u s e r_ a c c e s s ( )
, e x a m p le _ s o m e th in g ()
.
19.5 ,
, ,
, , .
xray_form_alter() (
?) (
-?).

412

19.

19.5. xray_form_alter()

xray_form_alter(&$form, &$form_state, $form_id) {


i f (variable_get(xray_show_formid', TRUE) && user_access(
'view xray messages')) {
$form['xray_display_form_id'] = array(
'#type' => 'item ',
'#theme_wrappers' => array( ' container xray form') ,
'#attributes' => array('c la s s ' => array( xray') ) ,
'# t it ie ' => t('Form ID'),
'#markup' => $form_id,
'#weight' => -100,

);
}
}
, :
i f }.
. ' xray_show_formid'
TRUE user_access TRUE,
'xray_display_form _id'.

. variable_get()!
,
FALSE. variable_get()
: ,
.


,
Drupal, , Drupal.org PHP.net .
;
Drupal . Drupal-
, , , .

JavaScript ,
Drupal. , . , Drupal
API- JavaScript. JavaScript Drupal
. , Drupal
J Query, JavaScript,
.


X-ray t()
format_plural().
. X-ray
, Drupal.
,
.

413

comma separated list


- - .
, 19.6.
19.6. Oxford C o m m a

/**
* .

* www.drupaler.co.uk/blog/oxford-comma/503
* , ,
* ', b '.

* @param $list
* .
* @param $settings
* Oxford comma:
*
- type
* . 'and'.
*
'or' 'and' ; .
*
- comma
* . .
* , , '; '.
*
- oxford
* 'TRUE'.

*/
function xray_oxford_comma_list($list, $settings = array()) {
// .
$comma = ', ';
$type - and';
$oxford = TRUE;
// ,
extract($settings, EXTR_IF_EXISTS);
// 'and' 'or',
if ($type == 'and') {
$type = t('and', array(), array('context' => 'Final join'));

>

elseif ($type == 'or') {


$type = t('or', array(), array('context' => 'Final join'));

>
//
if ($oxford && count($list) > 2) {
$final_join = $comma . $type . ' ';

>

else {
$final_join = ' ' . $type . ' ';

// $list .
$final = array_splice($list, -2, 2);
// .
$final_string = implode($final_join, $final);
// .
array_push($list, $final_string);
// , ,
return implode($comma, $list);

}
, . .

414

19.

t( ) , , and
.
- extract().
, . (
.) dgd7.org/245
,
, extract().
Drupal ,
. , , .
, .
, ,
. xray_oxf ord_comma_
list () ,
. ,
, .


, .
. .
, , .



. ,
, - Drupal.


, , (,
home).
, .
Drupal.org.


. , ,
. ,
.
, .


, , . ,
.
, (
) , . ,
(IDE)
.

Vim (. dgd7.org/vi).

415

Drupal ( )
.
, .
, , .
.
,
.


, ,
,
( ),
. , ,
( ), :
Fatal error: Cannot use object of type stdClass as array in
/home/ben/code/dgd7/web/sites/default/modules/xray/xray.module on line 186

.
. ,
, (White Screen of
Death, WSOD). ,
. ,
Devel. 28
.
.
186, . 19.7
.
19.7.
<?php
// 186 :
if (isset($theme['info']['hidden']) && $theme['info']['hidden'] == TRUE) {
/ / ...

>
// :
if (isset($theme->info[hidden']) && $theme->info['hidden'] == TRUE) {
/ / ...

}
?>
, ,
. , $theme
. , Cannot use object of
type stdClass as array ,
, (->).



, , . ,
- , .
, -

416

19.

, -,
. .
. 19.2 ,
-.
Warning: htm lspecialcharsO expects parameter 1 to be string, array given in check_plaln() (line 1476 of /home/ben/workspace/msg/lncludes

/bootstrap, inc).
Warning-. htmlspecialcharsO expects parameter 1 to be string, object given in checkj>(ain() (line 1476 of /homkAien/workspace

/msgrfncludes/bootstrap. inc).

. 1 9 .2 . Warning: htmlspecialcharsO expects parameter 1 to be string

, Warning, array given, warning, object given, on line


of bootstrap.inc? bootstrap.inc!
, , h tm ls p e c ia lc h a rs O
check__plain(). Drupal- 157
, c h e c k _ p la in ( ). , 157;
api.drupal.org/check_plain. , ,
c h e c k _ p la in () t ( ) ,
. 1246
Drupal-. , h tm ls p e c ia lc h a rs O
, , t ( ) c h e c k _ p la in (),
...
,
. ,
, dgd7.org/ides. Drupal
Devel,
PH P- . ,
Krumo. ,
.
1,476

Devel

Devel Drupal.
, Krumo ,
.
1. Devel drupal.org/project/devel
Drush-: drush d l devel,
(Moshe Weitzman), Devel, Drush.
2. admin/modules Drush: drush - en devel.
3. admin/config/development/devel (
Configure admin/modules).
4. , Error handler
Backtrace. , Save
configuration.

, ,
.
htmlspecialchars ()
(. 19.3).

5.

417

W arning: htm lspecialcharsO e x p e c ts p a r a m e te r 1 to b e string, o b jec t g iv e n in h tm lsp ecia lch a rsO (line 1476 of /h o m e /b e n /w o r k s p a c e
/m sg /in clu d es/b o o tstra p .in c), = >

ru m

version

0 . 2 . 1 a | h ttp /ftru m o . o u r c e f o rg e n#j

. 1 9 .3 . Warning: htmlspecialcharsO expects parameter 1 to be string

Devel Krumo

, . ...(Array,
,
19 , , Krumo (. 19.4).

19 elements),

Warning: htmlspecialcharsO expects parameter 1 to be string, object given in htmlspecialcharsO


(line 1476 of /home/ben/workspace/msg/includesA>ootstrap.inc). = >

54 foments)

ttw n e (Arroy, 4
S

i&s-i' iwSww'1

.....

xratv show M o e callback (Array 4 efomontsi

, -

menu_gt_acttve_hlp (A/ray, 4 etomettis)


2

,-

e#OTrwnfer)
IS

&

A-..

i$? y;: '


dfliOAl fu n rtn f OAQti iA rm v 4 nfMi

K r u m o version 0.2, Is | http://Krumoeourcefor9e.net

. 1 9 .4 . Krumo

Warning: htmlspecialcharsO expects parameter 1 to be string

, h tm ls p e c ia lc h a rs O . ,
, , , ,
menu_execute_active_handler(). index.php
Drupal ( 28 Drupal ).
X-ray, , ,
.
theme_xray_show_callback
. , page_arguments
, xray_show_page_callback().

Devel , Drupal
, debug(debug_backtrace());,
, , Krumo.

418

19.

,
.
drupal_placeholder(). ( )
,
.



Drupal. Node
template_preprocess_node() ( preprocess,
, grep -nHR ' preprocess' modules/node).

Drupal 7
.
template.php.

, .
drupal.org/node/933976
.


template_ ( ).
preprocess_, .
hook_theme() ; Drupal
. ,
. , {variables
, .
19.8.
1 9 .8 . ,
theme_xray_show_page_callback()

/**
* .

*/

function template_preprocess_xray_show_page_callback(&$variables) {
if ($variables['page_arguments']) {
foreach ($variables['page_arguments'] as $key => $value) {
// ,
// .
if (is_array($value)) {
$value = t('array') . ' ' . $key;

elseif (is_object($value)) {
$value = t('object') . ' ' . $key;

// .
$variables['page_arguments'][$key] = drupal_placeholder($value);

}
}
}
/**
*
* .

419

* ( $variables
*
, menu_get_item(), :
*
- page_callback: , -.
* - page_arguments: () ,
*
.
*
- include_file: () ,
* ;
* .
*

* @see template_preprocess_xray_show_page_callback()
*
* @ingroup themeable

*/
function theme_xray_show_page_callback($variables) {
extract($variables, EXTR_SKIP);
$output = '';
$output .= '<p class="xray-help xray-page-callback">';
$output .= t(This page is brought to you by );
if ($page_arguments) {
$output .= format_plural(count($page_arguments),
'the argument !arg handed to ',
'the arguments !arg handed to ',
array('!arg' => xray_oxford_comma_list($page_arguments))

);
}

$output .= t('the function %func',


array(*%func' => $page_callback . '()'));
if ($include_file) {
$output .= t(' and the included file %file',
array('%file' => $include_file));

>

$output .= '.</p>';
return $output;

}
,
. ,
, ,
dgd7.org/61.
.

19.8 ( ), ,
Krumo. ,
, dgd7.org/259.


, (API),
, ,
? , ! -
( ),
dgd7.org/code.

420

19.

,
, ;
, .
, .
, ,
. , .
, ,
.
.
Coder review ( ).
, , , .
,
? , ,
?
, , ,
. , Database API SQL-,
HTML- JavaScript-,
t( ) , check_plain() f ilte r _ x s s ( ).
6.
(. drupal.org/coding-standards).
Coder review.

.module, , ,
?
. ,
( ).
, .module,
. (
28). ,
, .

Coder Review
,
Coder review, Coder (drupal.org/project/coder).
.
Coder review ( drush d l coder drush
- en coder_review). Configuration
Development Coder (admin/config/development/coder).
, . ,
Drupal, ,
SQL, . minor,
.
Select specific modules.
.
- : Coder found 1 projects, 3 files, 1 critical warnings,
12 normal warnings, 9 minor warnings, 0 warnings were flagged to be ignored. ,
- ,
Database API. ,

421

, Coder review: t ()
. ,
. ,
. ,
, , .
, ,
, .


Drupal
.
(twitter.com/mrf)

,
. ,
Drupal.
Drupal.org, .
.

. .
IRC-.
, - groups.drupal.org.
Peer Review, groups.
drupal.org/peer-review. , ,
. ,
- ,
. :
Drupal.org.
, .
, .
task, needs review. (
, ).
, ,
.
peer-review ( peer review).
, . , ,
: code-review, uxreview, accessibility-review . .
groups.drupal.org/peer-review/requests.
. ,
needs review needs work (
). Assigned
, ,
,
, .
needs review.
,
, , ,
Reviewed and Tested by the Community (RTBC).

422

19.

Reviewed by
( ) on ( ).
, .
, .
IRC- (. 9).
Drupal!

,
, (drupal.
org/coding-standards).

,
, .
,
. , -
, , .
, ,
. , -
.

hook_help()
hook_help() , Drupal.
.
hook_help()

. ,
, , (
). , ;
. API.

hook_help() HTML-, ,
Drupal 7 .

$path $

, , . $path,
, hook_help(),
Drupal , . Drupal
, hook_menu(). ,
, , admin/structure,
admin/structure, , ,
node/1, node/%. ,
( , ) hook_help(),
, , $arg.

hook_help(),
path arg. test ( , ,
, X-ray) .
test.module 19.9. test.

423

info
.
1 9 .9 . test.module

<?php
function test_help($pathj $arg) {
return $path . '<pre>' . var_export($arg, TRUE) . '</pre>;

}
, xray. module's xray_help()
.

Drupal
debug(): debug($path, path'); debug($arg, arg'); , , .
, , ,
TRUE.

, node/add/article ,
(article): node/add/article.

,
node_menu(). ,
, .
admin/structure/types/manage/article,
Article, $path : adm in/structure/types/
manage/% ( a rtic le %, ).
, ,
$arg, , ('adm in',
's tru c tu re ', types', 'manage' 'a r tic le ') .

hook_help() X-ray (
).
,
.
, , , , ,
hook_help() -. hook_help()
admin/help, (#) (
admin/help#xray), Drupal
admin/help/xray admin/help.

X-ray ( , ).
1 9 .1 0 . -

/**
* hook_help().

*/

function xray_help($path, $arg) {


$help = ";
// ,
// .
$help .= xray_show_page_callback();
switch ($p ath ) {

&

424

19.

1 9 .1 0 ()

// ,
case 'admin/content':
$variables = array('data' => xray_content_summary());
return $help . theme('xray_content_summary', $variables);
case 'admin/structure':
$variables = array('data' => xray_structure_summary());
return $help . theme('xray_structure_summary', $variables);
case 'admin/appearance':
$variables = array('data' => xray_appearance_summary());
return $help . theme('xray_appearance_summary', $variables);
case 'admin/people':
$variables = array('data' => xray_people_summary());
return $help . theme('xray_people_summary', $variables);
case 'admin/modules':
$variables = array('data' => xray_modules_summary());
return $help . theme('xray_modules_summary', $variables);
// ,
case 'admin/help#xray':
// ;
// xray_show_page_callback $help .
return _xray_help_page();
default:
return $help;

>
>
/**
* X-ray.

*/
function _xray_help_page() {
$output = '';
$output .= '<h3>' . t('About') . '</hB>';
$output .= '<p>' . t('X-ray module provides a look at the skeletal
structure of your site from several perspectives intended to benefit
developers and site builders.') . '</p>';
$output .= '<p>' . t('It adds an accounting summary of relevant objects
to the help above the main administrative sections (blocks, content
types, menus on <a href="(8)structure"> Structure</a>; themes on <a href
="@appearance">Appearance</a>; etc)., array('@structure'=>url(
'admin/structure'), '(appearance* => url('admin/appearance'))) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Page callback and arguments') . '</dt>';
$output .= '<dd>' . t('X-ray exposes the function that is primarily
responsible for providing a given page in a help message at the top of
that page. It precedes the name of the function with the arguments
handed it, if any. It also provides the name of the file where this
function lives if available (the file is only available if the callback
does not live in a .module). Note that just because arguments are handed
in to a function does not mean they are used.') .
'</dd>';
$output .= '</dl>';
return $output;

}
,
, People Modules,
Structure. dgd7.org/252.

425

,
X-ray hook_theme(), hook_menu() (
) hook_help(). X-ray, ,

, , , . ,
17, 18 19 ,
, Drupal .

, 17,18 19 -,
dgd7.org/intromodule.

20. Drupal 7

, Drupal
.
.
,
, .
, ,
,
Drupal 7. Drupal 6
Drupal 7.
, Drupal.
Add another ,
.
add another. , .
, Drupal 6. ,
!
, ,
Drupal 7, ,
. :
;
, ;
Drupal, :
7.
.
. ,
, ,
API.


Drupal ,
Drupal-, , ,
. , -
Drupal .
- (
)
.

6 Drupal 7. , Drupal,
.

, , ,
. , *
.
Add another. drupal.org/
project/addanother; 6 Drupal 7 .

427

, ,
Drupal-,
- .
, .


,
, . .

http://drupal.org, . 20.1.
Download & Extend
Download & Extend Home

Orupai Core

Modules

th em es

Translations

installation Profiles

Add another
'CVS tftstfi-rttfom

edit Qut&Mfr:

'

Maintainers for Add another

Posted by . Monks an January 11, 2009 si 8:46pm

Add. another is designed to save time during repetitive


content creation, it allows the content creator to add
another node of the sam e type much faster. The user
interface modific ations it provides to achieve this include:

m-** *

Robm Monks - 40 commits


last: 3 days ago, first-, I year ago

Add another m essage displayed after the user creates a


node
* Add another tab on nodes to create further nodes of the sam e type
Save and Add another button on node creation forms to allow the user to quickly create
many rwdes of the sam e type (Drupal 7.X-2.X+ only)
Drupal 1 m oves the Add another settings onto the node type settings pages to allow finer
control. Prewous versions supplied a single configuration page to administer all node types.

Add another is an attem pt to check one of th e items (#5 on my list, actually) off the wish list on
my h bg. The first version was created in about 3Gmin.
Add another 2.x and higher include alt the functionality o f Submit Again and many more
configurable options, so >t is unnecessary to u se both modules, in version 1.x and before both
Submit Again and Add another m ay be u sed together without issue.

View all committers

issues for Add another


To avoid duplicates:, please sea:
submitting a new issu e
; Search ;
Advanced search

All issues
2 open, 17 total

Bug reports
0 open, 6 total
Subscribe via e-mail
r. 9 ju! 09

#D?CX: t pledge that this module will have a full Orupai 7 release on the day th at Drupal ? is
released.

Recent issues

Project information

Orupai 7 r

Maintenance status: Actively maintained


Development status: Under active development
Reported installs: 1394 sites currently report using this module. View usage statistics.
Last modified; October 28. 2010

altering the "add URL*

Downloads

Related projects

Recommended releases
V ersion
Downloads

Mollom Stats
Submit Again
Search Lucen APi
Field indexes
CCK Redirection

Date

Unks

7.x-2Q'beta2

Download fs 4s

201D-Oct-29

Motes j Edit

6.X-1.6

D o w n l o a d if .$7 KSS

2010- Apr-19

Notes 1Edit.

S.x-LO

Download i7.i5 kb)

2009-Oct-29

Notes | Edit

Version

Downloads

Date

?,X-1.0-beta 1

Download

Other releases

Development releases
V ersion
?.x-2-X-dev

2010-0ct-21

Downloads

Date

Download (3.48 m i

2O10-Oct 29

Unks

Notes j Edit

Links

Notes } Edit

Resources
View project translations

Development
View pending patches
Browse the CVS repository
View CVS m essages
Report a security issue

. 2 0 .1 . Add another,

428

20. Drupal 7

,
drupal.orQ/pro\ect/\ssues/UMH_npoeKma. Add another
drupal.org/project/issues/addanother?status=AII,
. ?status=AII

; .
, ;
( , , ,
, , ), (,
6.x 7.x) ( ).

Search for
:
Status (active, fixed);
Priority (major, minor);
Category (bug report, support request);
Version Drupal ;
Component (code, documentation).
Search,
.

. 20.2. Summary (
); Assigned to, -
; , .
Status (
).
. ,
Last updated ( ,
, ).
Download
Download

&

Extend

Extend H om e

Drupal Core j Modules ; Them es

Translations

installation Profiles

Add an o th e r

Issues for Add another


C reate a new issue Advanced se a rc h s ta tistic s Subscribe
Search for

Status

P riority

active

[* ]

C a te g o ry

- Any - Q

- Any -

V e rsio n

[;; :

. E

Com ponent
'

("Search]

Su m m a ry

S ta tu s

P riority

C a te g o ry

Version Com ponent R eplies Last


u pd ated

compatibility with nodere fe rre rM o d e re fe rre r c re a te


by altering th e *add URLe

active

m inor

fea tu re
req u e sts

.-1.3

Code

A ssign ed
to

37 weeks
3 days

Subscribe with RSS

. 2 0 .2 . Add another


, ,
Search for . Add another

429

Drupal 7, port 7.x version. ,


, .
Create a new issue ( Add another
drupal.org/node/add/project-issue/addanother).
Version;
7.x , 6.x. (
; )
7.x.
7. . : Component, (
, ), Category (,
, feature request bug
report). Priority, Assigned Status , .
: 7.x port.
, : This
simple and useful module needs a Drupal 7 port (
Drupal 7).

?
Drupal
, ,
.
. 21.
. ( )
, , . ,
,
.
, .
,
( ) . -,
, . ,
, ,
. -, ,
; -
:
Drupal 8, !


Add another Drupal 7,
6.x-1.6 (Presents users with an option to
create another node of the same type after a node is added).
Drupal This version is not compatible with Drupal 7.x and should be replaced.
, . 20.3.

, .
, . ,
, ,
.

430

20. Drupal 7

DESCRIPTION
P resen ts u se rs with an option to cre a te an o th e r n o d e of th e sa m e type a fte r a n o d e is a d d e d

This version is not com p atib le with Drupal 7 .x and shou ld b e rep la ced .
Allows se rv e r ad m in istrato rs to p rev e n t m o dules from beng d isa b le d .

. 2 0 .3 . , ,

Drupal

, , Add another
Drupal 7. ,
.info, -
.

,
API .
Drupal.org, Developing for Drupal Module
Developers Guide Updating Your Modules. , Drupal 6
Drupal 7, drupal.org/update/modules/6/7.
Drupal
Drupal-.
200
? ,
, .

( DX, Developer Experience).

()

(Jim Berry) (Jon Duell)


Coder Upgrade. Coder (drupal.org/
project/coder).

Grammar Parser,
. drupal.org/project/grammar_parser.

.

upgrade.boombatower.com.

, ,
, .
(
); Drupal 7 .
, Coder Grammar Parser
sites/all/modules. ,
.
Drupal Modules
(admin/modules). Coder, Coder Upgrade Grammar Parser (
Coder Upgrade).

431

, .
. -dev,
HEAD;
, ,
.
Add another ( http://drupal.org/project/addanother)
, .
( ) ,
. , 6.x-1.4
. ,
Coder Upgrade.
Drupal ( sites/default/files) coder_upgrade,
old (coder_upgrade/old). ,
sites/default/files/coder_upgrade/old. .

Drupal ( drupal7) :
drush dl coder grammar_parser
drush en coder coder_upgrade grammar_parser
mkdir -p sites/default/files/coder_upgrade/old
cd ../
drush dl addanother --default-major=6 --select -destination=drupal7/sites/default/files/coder_upgrade/old

-p mkdir parents; old


coderupgrade.

Drupal 7, Drush
Drupal 6. cd (change directory).

select drush
.


.
Coder Upgrade.

(. admin/help).
Coder Upgrade admin/help/
coder upgrade .

,
Configuration Development Coder Upgrade (admin/
config/development/coder/upgrade). Directories
, . .
Add another addanother. Coder Upgrade
coder_upgrade/old/addanother, ,
, .
Convert files, . 20.4.

432

20. Drupal 7

Home * Administration Configuration Development Coder

Settings
The purpose of this rnoduie is to autom ate as much as possible the task of updating a contributed module for Drgpal API changes This
particular moduie helps upd ate the 6 x version of a contributed moduie to the 7.x version API Relative to the Drupal core APIs, the list of
autom ated conversions to be applied is indicated here For more detailed instructions on the module conversion process, vtsit the beip page
U pgrades

Extensions

. resid in g in th e s e le c te d d ire c to ries (b en e a th th e fiies directory), o r ...


fj

addanother

! L O C A T IO N

coder_upgrade/old/addanother

D irectories

Modules

Convert files

. 2 0 .4 . Coder Upgrade ,

:
Module conversion code was run ( );
Click to view the conversion log file ( );
Patch files may be viewed by clicking on Name links in the Directories and Modules tabs
below ( , Name Directories
and Modules).
,
: .
. ,
Coder Upgrade.
, ,
.
, Coder Upgrade
(sites/default/files/coder_upgrade/new), sites/all/modules sites/default/modules.
6.x ,
Coder Upgrade. .

mv sites/default/files/coder_upgrade/old/addanother sites/default/modules/
patch -p0 < sites/default/files/coder_upgrade/patches/addanother.patch

Drupal drupal.org/patch/apply.

patch ( , ,
patch , patch - < --

copaec-cec-e.patch).
, ,
core .info 7.x.
, Drupal.org
- , (
, .info ).

433

, , ,
coder_upgrade core. ,
Coder Upgrade .install .module
files[ ].
Coder Upgrade, , .
name = Add another
description = "Presents users with an option to create another node of the same type
after a node is added."
core = 7.x
; Information added by drupal.org packaging script on 2010-04-19
version = "6.X-1.6"
core = 7.x
project = "addanother"
datestamp = "1271637006"

Drupal.org,
. Drupal
.info, .


(, ,
). - :
Configuration, Create content
. ,
. Add another
Configuration, .
, .
,
.
!


- , , ,
. ,
22,
, . , .
, - ,
, , ,
.
Add another Configuration.
,
, .
, , sites/default/modules.
addanother.module addanother.

:
cd sites/default/modules/addanother/
vi addanother.module

434

20. Drupal 7

, . ?
, Drupal,
hook_menu. Drupal 7
. Drupal 6 admin/settings/; Coder Upgrade : admin/config/.
, Drupal 7,
Configuration. , ,
.
system. admin/config/system/
. .
Coder Upgrade
/**
* hook_menu().

*/

function addanother_menu() {
$items = array();
$items['admin/config/addanother'] = array(
'title' => 'Add another',

}

/**
* hook_menu().

*/
function addanother_menu() {
$items = array();
$items['admin/config/system/addanother'] = array(
'title' => 'Add another',

}
Drupal
. . -,
Configuration, Performance Development
Clear all caches. -, Drush,
:
drush

Configuration Add
another. Add another page
Add another Article,
Drupal.
, Display the Add another message after
node creation, Display the Add another tab on supported node types Also display the Add another tab
on supported node edit pages, . 20.5.
, .
Article :
Notice: Undefined index: access in _menu_translate() (line 776 of
C:\xampp\htdocs\d7\includes\menu.inc).
Notice: Undefined index: access in menu_local_tasks() (line 1890 of
C:\xampp\htdocs\d7\includes\menu.inc).

435

Dashboard

Add content

Content

Structure

Appearance

People

Modules

Reports

Help

Hello a d m in

Fmd content

leg cut
edit shortcuts

Home * Administration *Configuration System


Add another

CONTENT SETTINGS
Enable Add an other for th e s e c o n te n t ty p es

jfrjArticle
|3 Basse page
An A d d another m essage will be shown after creating these content types

DISPLAY SETTINGS

Display the Add another m essage after node creation.


Display the Add another tab on supported node types.

\ Also display the Add another tab on supported node edit pages.
S a v e configuration

. 2 0.5 . Add another

, Drupal 7, Coder
. Drupal 6 Add another
addanother_access, Coder Upgrade ,
Drupal 7 addanother_node_access. ,
.
/**
Upgrade

* , Add another .

*/

function addanother_node_access($nid) {

}
, :
* , Add another .

*/

function addanother_access($nid) {

}
! , Add another
, Add another.
Drupal 7,
, drupal_set_message addanother_node_insert.
, ,
Submit Again.

436

20. Drupal 7

/**
* hook_node_insert().

*/
function addanother_node_insert($node) {
if ($node->op == t('Save and create another')) {
// Add another Submit Again,
return;

$allowed_nodetypes = variable_get('addanother_nodetypes', array());


if (user_access(1use add another') && isset(
$allowed_nodetypes[$node->type]) && $allowed_nodetypes[$node->type]) {
global $_addanother_message;
$_addanother_message = t('Add another <a href="(8)typeurl">%type</a>.',
array('@typeurl' => url('node/add/' . str_replace(
$node->type)), '%type' => node_type_get_name($node)

));
}
}
* hook_nodeapi().

*/
function addanother_nodeapi_OLD(&$node, $op, $a3 = NULL, $a4 = NULL) { }

/**

* hook_form_alter().

*/
function addanother_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node']) && $form['#node']->type . '_node_form' ==
$form_id && variable_get('addanother_message1j TRUE)) {
$form['buttons']['submit]['#submit'][] = '_addanother_message';

}
}
/**
* Add another, addanother_nodeapi().

*/
function _addanother_message($form, &$form_state) {
global $_addanother_message;
if (isset($_addanother_message)) {
drupal_set_message($_addanother_message, 'status', FALSE);

}

/**
* hook_node_insert().

*/
function addanother_node_insert($node) {
$allowed_nodetypes = variable get('addanother nodetypes', array());
if (user_access('use add another') && isset(
$allowed_nodetypes[$node->type]) && $allowed_nodetypes[$node->type]) {
$_addanother_message = t('Add another <a href="@typeurl">%type</a>.',
array('@typeurl' => url('node/add/' . str_replace(
3
$node->type)), '%type' => node_type_get_name($node)

));

drupal_set_message($_addanother_message, 'status', FALSE);

437

, hook_nodeapi,
_addanother_message hook_form_alter.
,
, Drupal 7.
DRUPAL 7
Drupal 7, ,
, Implements hook_somethingorother(). (.
drupal.org/coding-standards Module Documentation Guidelines
drupal.org/node/161085.) , implements,
Drupal 7.

, . 20.6,
, !

Dashfefeaa

Content

stn ;ture

Appearance

PenpSe

Modules

Crtfigu*attiri

"fteptfts

Help

HeHn ad m in

103 put
Edit shortcuts

Add content

Find content

Testbed

My account

Log out

1
^

* Add another Article

* Article Example article has been created

Home

Q.

Example article
View

Navigation

Edit ; Add another

Oevei

ptiwisheti fcyadmin on Fri, 01/14/2011 15:25

Acid co n te n t

This is only an example.

A dd

Development

new comment

Your name

adm in

. 2 0 .6 .


Drupal .
Drupal, ,
. , .

Examples
(drupal.org/projects/examples).

,
, , comment.module.

438

20. Drupal 7

Drupal.org, ,
, .

,
. , Comment (
, CSS- JavaScript-, .install .info) comment,
admin.inc, comment.pages.inc comment.tokens.inc.

,
,
Drupal. .

Drupal.org
,
.
.
( ).

, .
Drupal.org,
, .
, . ?
( )
.
Creating Patches drupal.org/patch/create.

. , .
,
, h ttp://w inm erge.org.
.
. UNIX- (Linux, Mac OS X
Cygwin Windows) ,
diff.
.
, Drupal-: (
) ,
, (
). , :
( ) ( ).
> ( ) ,
.
Drupal.org , ,
( ),
, .
, , .
,
. Add another Add another. (
Drupal Drupal.)

Drupal.org

439

drupal.org/project/issues/addanother 7.x port.


URL- http://drupal.org/node/554504.
, (
). ,
. , , :
cd sites/default/modules/addanother
diff - ../../files/coder_upgrade/old/addanother/ . > addanother-7.x-port-554504-5.
patch

Add another (
), patch.
, Add another Drupal 6
:
wget http://ftp.drupal.org/files/projects/addanother-6.x-l.4.tar.gz
tar -xzf addanother-6.x-1.4.tar.gz
cd addanother
patch -p0 < ../addanother-7.x-port-554504-5.patch

, , .
, .patch.
, ,
, . ,
.

, ,
. Drupal-!


dgd7.org/upmodule.

21.

Jlopema

Drupal ,
,
.
.
,
; ,
.
(glue code),
.
100 %, .

,
. ,
.

:
(core module) Drupal.
, .
(contributed module) Drupal.org.
,
.
(custom module)
.
, , .


Drupal, .

Drupal.org , ,
.
,
.
, Drupal-,
.
, ,
Drupal-, ,
.
,
, .
,
. Drupal,
index.php.

441

modules.
.
sites/all/modules/contrib.
.
sites/all/modules/custom.
, , .
sites/
all/modules/custom :
,
, myproject_comment.module.
.
, , .
,
.info.
, , Project,
:
sites/all/modules/custom/myproject_comment/myproject_comment.info
name = "MyProject Comment Customizations"
description = "Customize the comment form for MyProject."
core = 7.x
package = "MyWebSite"
; , ,
dependencies[] = comment
sites/all/modules/custom/myproject_comment/myproject_comment.module
<?php

myproject_comment.module .
, .

, ,
; .
, .

, ,
. ,
, Drupal .

. , hook_comment_presave(),
. ,
, ,
hook .
myproject_comment, hook_comment_presave,
:
function myproject_comment_comment_presave($comment) {
// - .

442

21.

,
.
Drupal .
-,
.

.

, , , .
, (API)
,
. ,
,
, :
?
?
?
?

?
,
, ? ,
, .
.
, , ,
, .
, ,
.

?
Drupal ,
.
.
.
.
. , Drupal
, ,
, ,
.
, , ,
. , ,
, . ,
, .
,
, . ,
. api.drupal.org,
. 21.1.

443

2 1 .1 .

hook_form_alter(&$form, &$form_state, $form_id)


hook_node_presave(), hook_node_insert() . .
hook_menu_alter(&$items)

?
,
, . ,
debug (). ,
,
.

Devel ,
Drupal.
,
.


?
, , , . ,
,
; . , ,
, .

: Submit
:
1. ?
, , ,
, Save
Store this information.
2. ?
,
, hook_form_alter(),
: $form, $form_state $form_id:
function mymodule_form_alter(&$form, &$form_state, $form_id) {

}
3. ?
Devel dpm(),
:
function mymodule_form_alter(&$form, &$form_state, $form_id) {
dpm($form);
dpm($form_state);
dpm($form_id);

444

21.

, $f Form API,
, . 21.1. -
. $form_state
, . $f orm_id
. ,
- .
... [Array, 38 elements)
#node_editJ o r m (Boolean) TRUE
attributes (Array, 1 element)
nid {Array. 2 elements)
vid (Array, 2 elements)
uid (Array, 2 elements)
created (Array 2 elements)
type (Array, 2 elements)
language (Array, 2 elements)
changed (Array. 2 elements )
title (Array, 6 elements)
#node (Object) stdClass
addHionai_settings [Array, 2 elements)
revisionJnformstion (Array. 11 elements)
author (Array, 11 elements)
options (Array, 12 elements)
actions (Array, 3 elements)
#valldate (Array 1 element)

#submit (Array. 0 elements)


#parer>ts (Array, 0 elements)
body (Array. 6 elements)
fteidjmage (Array, 6 elements)
#pre_render (Array 1 element)

#entity_type (String, 4 characters ) node


#bundte (String, 7 characters ) article
#formJd (String, 17 characters) article_nodeJorm
#type (String, 4 characters ) form
#buidJ d (String, 48 characters) form-KLftEWcCNunpa8UgBxtSa3CoUQcPmUljaJrTOaDq9Jo
form_buildJd (Array. 4 elements)
#token (Strina. 17 characters i article node form

. 21.1. dpm()

, hook_form_alter() ,
. hook_form_FORM_lD_alten()
$form_id.
,
.
4. ?
, , ,
. ,
hook_form_FORM_ID_alter().
article_node_form,
:
function mymodule_form_ article_node_form alter(
&$form, &$form_state, $form_id) {

445

// #value submit.
$form['submit1]['#value'] = t('Store this information');


, Drupal , .
api.drupal.org,
.
.


,
. , ,
,
. , ,

, .
,
. , ,
.
, :
/**
* hook_form_alter().
* .

*/

function mymodule_form_alter(&$form, &$form_state, $form_id) {


$form['comment_settings']['#access'] = FALSE;

}
, hook_form_alter()
#access FALSE,
. ,
.
,
,
.
.
, ,
. TRUE
FALSE, .
/**
* hook_menu_alter().

* http://example.com/node .

*/

function mymodule_menu_alter(&$items) {
$items['node']['access callback'] = FALSE;

}
, .
.
. .

446

21.


. ,
. ,
,
.
/**
* hook_form_FORM_NAME_alter().

*
* .

*/
function mymodule_form__views_exposed_form_alter(&$form, &$form_state) {
// .
$form['title*]['#type'] = "select";
// Drupal Open Source.
$form['title']['#options'] = array(
=> t('List everything'),
'Drupal' => t('List only articles whose title includes "Drupal'"),
'Open Source' => t(
'List only articles whose title includes "Open Source"'),

);
}
.
,
, . ,
MENU_LOCAL_TASK MENU_CALLBACK:
/**
* hook_menu_alter().

*
* .

*/
function mymodule_menu_alter(&$items) {
// MENU_LOCAL_TASK, .
$items['node/%node/edit']['type'] = MENU_CALLBACK;

}
/**
* hook_node_view().

* .

*/
function mymodule_node_view($node, $view_mode) {
$node->content['links']['mymodule_link'] = l(t(
'Edit'), 'node/' . $node->nid . '/edit');


.
, , ,
, . , ,
, .

447

.
h o o k _ in s ta ll(). (
h o o k _ in s ta ll( ) Devel devel.install.)
. ,
, modules, ,
, , , sites/all/modules.
, .
hook_module_implements_alter(&$implementations, $hook).
, ,
. :
/**
hook_module_implements_alter().

*/
function mymodule_module_in\plements_alter(&$implementations, $hook) {
if ($hook == 'form_alter') {
$my_hook_implementation = $implementations['mymodule'];
unset ^implementations['mymodule']);
$implementations[mymodule'] = $my_hook_implementationj

}
}


Drupal 7
Fields API . ,
Field API
-. ,
.
, , .
Drupal 7 Fields API.
:
$entity->field_name[language_code][delta]['attribute_name']

,
Devel, :

f ield_, . ,
, body. ,
, field_.
' und ,
LANGUAGE_NONE.
.
, field_tags, .
f ield_language(),
field_get_items(), :
/**
* hook_node_presave().

*/
function mymodule_node_presave($node) {
// field_language().
$body_language_code = field_language(
'node', $node, 'body', $node->language)j
$body_value = $node->body[$body_language_code][0]['value'];

448

21.

// .
$body = field_get_items('node', $node, 'body');
$body_value = $body[0]['value'];

>
, ,
, #language
:
/**
* hook_form_alter().

*/

function mymodule_article_node_form_alter(&$form, &$form_state) {


// : $body_language_code = $form['body']['#language'];
// : $body_language_code = field_language(
//
'node'j $node['#node'], 'body');

>
d e lta ,
. ,
.
0.
// .
foreach (field_get_items(
'node', $node, 'field_tags') as $delta => $item) {
// - .

>
. ,
, , value,
. tid
. Image
, . ,
, Devel.
, .

Field API ,
.

. Field API
api.drupal.org/api/drupal/modulesfield--field.module/group/field/7.



Web 2.0 JavaScript Ajax,
. , Drupal 7
,
.

jQuery UI
jQuery UI
, Drupal 7 jQuery.

449

,
, .
JavaScript-, ,
.
21.1 j Query UI
hook_page__alter().
21.1. jQuery UI

/**
* hook_page_alter().

* .

*/
function mymodule_page_alter(&$page) {
if (isset($page['sidebarjfirst'])) {
11 HTML- .
$page['sidebar_first]['#theme'] = 'mymodule_sidebar_accordion';
// accordion jQueryUI.
$page['sidebar_first']['#attached']['library'] = array(
array('system', 'ui.accordion*),

);
// .
$page['sidebar_first']['#attached']['js'][] = array(
'data' => '(function($) {
Drupal.behaviors.sidebarAccordion = {
attach: function(context, settings) {
$(#sidebar-first").accordion();

}
>5

})(jQuery);',
'type' => 'inline',

);
}

#ajax #states
. # ja x # s ta te s Form API
, Ajaxified-
. jQuery-,
PH P-
h o o k _ fo rm _ a lte r( ).
api.drupal.org/api/drupal/developertopicsforms_api_reference.html/7.


, ,
, ,

, ,
. ,
.

450

21.


, ,
. ,
.
.
, ,
. :
/**
* hook_node_view().

*/
function mymodule_node_view($node, $view_mode, $langcode) {
$display_outdated = $node->type == 'article';
$age = time() - $node->created
$is_outdated = $age > 60*60*24*7;
if ($display_outdated && $is_outdated) {
drupal_set_message(t(
'This article was posted over 1 week ago and might be outdated.'));

}
}
,
, story,
, .
- , .
:
/**
* hook_node_view().

*/
function mymodule_node_view($node, $view_mode, $langcode) {
$delay = variable_get('mymodule_outdated_delay_' . $node->type, 0);
$age = time() - $node->created
$is_outdated = $age > $delay;
if ($delay && $is_outdated) {
$type = node_type_load($node->type);
drupal_set_message(t('This @type was posted over @delay ago and might
be outdated.', array('@type' => $type->name, '@delay' =>
format_interval($age, 1));

}
}
.
, .
,
, 21.2.
2 1 .2 .

/**

* hook_form_FORM_NAME_alter().

*/

function mymodule_form_node_type_form_alter(&$form, &$form_state) {


$form['mymodule_outdated_delay'] = array(
'#title' => t('After how long do you want to warn users.'),
'#type' => 'select',
'#default_value' => variable_get('mymodule_outdated_delay_' .
$form['#node_type'], 60*60*24*7),
'#options' => array(

451

0 => t ('Do not warn about outdated content),


60*60 => t('1 hour' ),
60*60*24 => t('l day*),
60*60*24*7 => t('l week' ),

b
);
}

. ,
, hook_node_view(). ,
,
, .


, ,
. 21.2
, ,
, .
,
. , ,
, , ,
. hook_node__info() ,
hook_views_def ault_view() .
. ,
.
Features, . ,
31.


, ,
, , ,
. - Drupal
,

.

Drupal
, Drupal ,
.
, , ,
, Drupal-,
.
Drupal
drupal.org/codingstandards.


, ,
.

452

21.

, Drupal.org.
( ,
,
.)
Drupal- GPL 2.
( ,
), ,
.

, .
, . ,
, .


.
, . ,
, ,
. ,
( )
,
.

. ,
:
: -
.
, ,
.
, ,
, .

, .

, .
.
.
, .
,
, .


, ,
, .
Drupal.org , ,
, .
drupal.org/node/7765.
:

453

,
Drupal.
, ,
.
, .
, .
.
.

Drupal
.
Drupal 7 . API

, Drupal-.
Drupal. ,
,
.

, /
dgd7.org/glue.

22.


Simpletest

Drupal 7 ,

.
-,
. , Drupal 7,
, , .
, , ,
, -
.
Drupal :
( ).
, square_root() 9 ,
3.
,
, , .
Drupal
(modules/node/node.test), , ,
page, Add content Basic
.
,
Drupal . Drupal Simpletest . ,
Simpletest Drupal ( Drupal 6, . drupal.org/simpletest).

Drupal,
.
Simpletest
(
17). ,
, . ,
, 25
!, 25
.

25
. , 25
! , . Simpletest
,

Simpletest

455

Drupal,
.
,
. Simpletest. , Simpletest Drupal 7. (
, , .)

Simpletest
, , ,
Simpletest.
( !),
Simpletest . ,
. ,
. :
Drupal
, .
( ,
) .
.
, , , Drupal (. modules/
node/node.test), ,
.
( ). ,
.
.
.
(
),
.
, , ,
. , .
, ,
.

Simpletest
, Simpletest .
, Simpletest
:
, ;
, ;
, ;
,
.

. , , ,
. , ,

456

22. Simpletest

. :
.


(Test-Driven Development, TDD)
. TDD-:
(, ,
).
( ).
.
TDD-
, .
,
. TDD- :
1. , .
.
2. ( ), .
3. , ,
.
, !
, , .

Simpletest
Drupal-, ,
( !) .
Drupal, Simpletest (.
).
. , , ,
.
? Drupal-
: mymodule.info mymodule.module. (
. 17.) mymodule.test. ,
sites/all/modules/mymodule/mymodule.test.

Drupal 7 , , .info.
.test .info : files[] = mymodule.test.


.test, dgd7.org/167
www.apress.com.
, Drupal.
,
( , , ).
Simpletest (.
). ( ,
, ).

457

Drupal .
.

, ,
, .
. ,
, (. drupal.org/node/666956 drupal.org/project/
simpletest_clone), .

Simpletest , ;
. Simpletest ,
( Simpletest),
; ,
.


( Simpletest), ,
. Simpletest ,
, .
,
, .
.


Drupal 7 Simpletest,
.
Drupal, . .
, ,
, .
Drupal (, )
. ,
Simpletest .
, .
Simpletest .

Simpletest simpletest, admin/modules


Testing, . 22.1.
Drush (. 25), drush en simpletest.

, Drupal:
, .
Drupal 7, Testing,
Configuration Testing Development.
( ), .
blog Run tests.
( ; ),
Drupal
,

458

22. Simpletest

. ,
.
Modules j Simpletest Book
i

hup //example.corn/#overlay==admm/rnodules

. 2 2 .1 . Testing

results , 250
verbose messages.
. , HTML ,
. , ,
, .

Simpletest,
Configuration Development Testing Settings (admin/config/development/testing/
settings) Provide verbose information when running
tests. , HTML, , , .
. .

.test
.test (, modules/node/node.test)
, - ,
Drupal-.
, 22.1.

.test

459

.test,
.module .info.
.info (. Simpletest).
22.1. .test
<?php

/**

* file
* .

*/
/**
*
*
*
*
*
*
*

.
Simpletest.
.
Simpletest
Drupal,
, .
.test .

*/
class MyModuleTestCase extends DrupalWebTestCase {

/**
* .

*/
public static function getInfo() {
return array(
'name' => 'One-line description of your test case',
'description' => t('Longer description of your test case.'),
'group' => 'mymodule',

);
}
/*
* .

*/
public function setUp() {
// ,
// mymodule ,
parent::setUp('mymodule');
// ; .
$admin = $this->drupalCreatellser(array(
'permission one', 'permission two'));
$this->drupalLogin($admin);

}
/*
* , 'test'.
* Simpletest Drupal,
* setup() .

*/

public function testMainTest() {


// . ,
// setup() ,
// , .

460

22. Simpletest

- , , ,
, ,
.
,
.
test. Simpletest .
,
, Drupal.

.


,
.
, Over 25 active users! (
25 ) .
, , .
,
25 .
, , ,
mymodule. mymodule sites/all/modules.
22.2 sites/all/modules/mymodule/mymodule.module (
dgd7.org/167
www.apress.com).
22.2. mymodule.module
<?php

/**
* (Sfile
* , t('Over 25 active users!'),
* 25 30 .

*/
/**
* hook_block_info().

*/
function mymodule_block_info() {
$blocks[0]['info'] = t('Number of users');
return $blocks;

}
/**
* hook_block_view().

*/

function mymodule_block_view($delta = '') {


if ($delta == 0 && mymodule_active_users() >= 25) {
$block['subject'] = t('Number of users');
$block['content'] = t('Over 25 active users!');
return $block;

>
}
/**
* mymodule_active_usersO.

.test

*
*
*
*

461

, ,
30 .
@return
(. ).

*/
function mymodule_active_users() {
return db_query('SELECT COUNT(DISTINCT uid) FROM {node} WHERE
:time - created < ithreshold', array(
':time' => REQUEST_TIME,
'ithreshold' => variable_get('mymodule_threshold', 60*60*24*30),

))

->fetchField();}

, Over 25 active users!,


mymodule_active_users() 25 .
, .
Simpletest 25
, .
! sites/all/modules/mymodule/mymodule.test
22.3.
22.3. mymodule.test
<?php

/**

* @file
* mymodule, ,
* Simpletest.

*/
/**
* ( ).
* .
* .

*/
class MyModuleTestCase extends DrupalWebTestCase {

/**
* .

*/
public static function getlnfoQ {
return array(
'name' => 'mymodule functionality',
'description' => t('Test the functionality of mymodule'),
'group' => 'mymodule',

)J
}
/*

* .

*/
public function setUp() {
// ,
// mymodule ,
parent::setUp('mymodule');
// ; .
$admin = $this->drupalCreateUser(array('administer blocks', 'create blog
content', 'administer nodes'));

&

462

22. Simpletest

22.3 ()
$this->drupalLogin($admin);
//
// sidebar_first, , Simpletest.
// , drupalPost().
$this->drupalPost('admin/structure/block', array('blocks[mymodule_0]
[region]' => 'sidebar_first'), t('Save blocks'));

}
/*
* 'test'.
* Simpletest Drupal,
* setup() .

*/
public function testMainTestQ {
// , setUpQ .
$this->assertNoText(t('Over 25 active users!'), t('Make sure the block
is not yet visible, because no content has been created yet.'));
// 25 .
for ($i = 0; $i < 25j $i++) {
// .
$user = $this->drupalCreatellser(array('create blog content'));
// , admin.
// , ,
// ,
// Save.
$this->drupalPost('node/add/blog', array('title' =>
$this->randomName(32), 'name' => $user->name), t('Save'));

>

$this->assertText(t('Over 25 active users!'), t('Make sure the block


is now visible, because we just created 25 users and a blog post for
each.'));

}
>
sites/all/modules/mymodule/mymodule.info,
22.4.
22.4. mymodule.info
name = My Module
description = Displays t('over 25 active users') if 25 users or more have
posted at least one node in the last month. This module was created to
demo simpletest as part of the book definitivedrupal.org.
dependencies[] = blog
files[] = mymodule.test
core = 7.x


, ! .
Drupal 7 Simpletest.
, ,
Configuration Testing
Development (. 22.2). , .
!

463

. 2 2 .2 .

'

AsJjS zonteM

......

-,

...

Mudutf

&B&

HHVioot

,*

find .!-

i "\
Edit sHortttns

te s t result
Howse * Adfnmi.vHati&n * Configuration Development * Ttesttn#

The test run finished in 1 min 48 sec.

ACTIONS
F ilm

Run te s ts

Return to list

RESULTS
189 passes, 0 fails, 0 exceptions; and

~Adebug n u is a g e i'..

MYMODULE FUNCTIONALITY

Test the functionality of mymodule


1.89 passes, 0 fails. 0 exceptions, and 54 debug m essages
MESSAGE

GROUP

FILENAME

LINE

FUNCTION

STATUS
^

Created role of name: hlkLDiuu, id: 4

Role

mymodule.test

34

MyModuieTestCase>setUpO

Created permissions: administer blocks, create blog content,


administer nodes

Role

mymodute.iest

34

MyModuieTestCase ~
>setup{)

User created with name sMvbEPuP and pass VCPmpaj9a

User
login

mymodule.test

34

Browser

mymodule.test

35

MyModuieTestCase +
>setUpO

v*.

Browser

mymodule.test

3S

MyModuieTestCase>setUpO

Debug

mymodule.test

35

MyModuieTestCase >setUpO

GET http://iocalhost/5impietestfaook/user returned 200 {7.42

:m .

Valid HTML found on "http://localhost/simpletesibook/user4

: J Verbose message

MyModuieTestCase>setUpO

. 2 2 .3 .

Simpletest ,
. . Performance
Development Clear all caches.

464

22. Simpletest

, . 22.3,
Simpletest ,
25 ,
, Over 25 active users!
.
. 22.3,
, assertText (),
, , drupalPost (),
, 189! 189 ?
Simpletest
.
Simpletest, :
25 .module 50 ( .test
), . ,
.
Verbose messages

, , :
Over 25 active users! , 25.
. , ,
25. , .
!

Simpletests
22.3
. , Simpletest ,
setUp().
Simpletest.
Simpletest
. , Simpletest .
.
Simpletest drupalPost(). 22.3
:
$this->drupalPost('admin/structure/block', array('blocks[mymodule_0]
[region]' => 'sidebar_first'), t('Save blocks' ));


, .
:
1. , .
http://e;ra/H/?fe.com/#overlay=admin/structure/block (example.com
). Drupal-
URL- admin/structure/block.
2. , ,
, , , Firebug Firefox. HTML .
<select name="blocks [mymodule_0] [region]" . . . >, ,
blocks [mymodule_0] [region], . 22.4.
3. . sidebar_
first, . 22.4.

465

API Simpletest

4. , ,
t ( ' Save blocks ), . 22.4.

f*

t().

Oine 685) (?
outocomplete.
*
input.form -text,
in p u t.fo rm -file ,
textorea.form tex tarea,
s e le c t. formselec t

bocfeground: none
repeat s c ro ll 0

tfPW
F;
border-

color: **< #CCCCCC.


#CCCCCC;
b o rd e r'rig h t: lpx
s o lid KCCCCCi
borders ty le : so lid ;

. 2 2 .4 .

, Simpletest
sidebar_f irst:
$this->drupalPost('admin/structure/block, array('blocks[mymodule_0]
[region]' => 'sidebar_first'), t('Save blocks'));

,
. 22.3:
$this->drupalPost('node/add/blog', array('title' =>
$this->randomName(32), 'name' => $user->name), t('Save'));

,
,
Save. ,
Drupal , Add content Blog entry (node/
add/blog) Firebug Firefox, ,
( ' t i t l e ' ' name').

API Simpletest
Simpletest, ( )
, - PHP-.

466

22. Simpletest

API Simpletest.
.
22.3;
.
. ,
$this-> ( 22.3).
drupalGet('path')

Simpletest .
drupalPost('path', array('inputl' => 'valuel',
'input2' => 'value2', t('Button Name))

Simpletest ,
.
assertText('text')

.
assertNoText('text')

.
assertRaw('html')

HTML- .
assertNoRaw('html')

HTML- .
$user = drupalCreatel)ser(array(permission 1', 'permission 2'))

,
drupalLogin($user)

, drupalCreatellser().
randomName()

,
.
verbose($text)

. .
, Simpletest:
Simpletest api.drupal.org/DrupalWebTestCase.
Drupal,
. Drupal 7 , modules/
contact/contact.test or modules/node/node.test.

modules/simpletest/drupal_web_test_case.php
, Simpletest.
Simpletest drupal.org/simpletest.
, ,
drupal.org/project/examples.

Drupal.org
( !) Drupal
.

467

. Drupal
, ( ) Drupal.org,
( ) .
Simpletest.
, ,
. , ,
.
,
Drupal.org,
? :
1. .test, .
2. , .
3. ( ), .
4. .
5. Drupal.org.


.
,
. :
Drupal ,
. ,
.

.
, .
. ,
. ,
, - ? .
, t e s t . . . ( ) ,
, , ,
Drupal, .
. ;
.
Provide verbose information when running tests
Simpletest (admin/config/development/testing/settings). ,
.

Drupal .

dgd7.org/test.

23.

, , .
( Think)

,
, .
, Drupal:
. (, , Drupal .)
,
, . Drupal
,
.

, , ,
Drupal- . Drupal
GNU General Public License (GPL). ,
, , ,
. , ,
, ,
.

(basic module) ,
Drupal, (major module) ,
. (
), Drupal. LoginToboggan
(drupal.org/project/logintoboggan) ,
Drupal, Advanced help (drupal.org/project/advanced_help) ,
.
API-,
API-.
(Application
Programming Interface, API), .
(
). ( 18),
, , API Drupal.
, ,
, , Drupal 7.
Form messages . (
AJAX form messages, ,
, AJAX- .)
, ,
API .
API Form messages
. ,
, API:
Drupal ( )

469

.
(
dgd7.org/strategy, ).
:
( ),
API.
Drupal 7 : .


.
,
. , ,
.
, ,
,
- ? Drupal.org
, groups.drupal.org (
g.d.o) Contributed Module Ideas, groups.
drupal.org/contributed-module-ideas. (
groups.drupal.org/node/add/story?gids[]=5445). ,
, URL- , g.d.o-
story,
5445. ,
! ,
IRC-, #drupal-contribute.

, ,
.
,
, ,
. drupal.org/
node/23789.

Form Messages, Drupal AJAX


form messages, drupal AJAX form validation drupal inline form validation
. , , Contributed Module Ideas Form
API and Usability ( groups.drupal.org/node/113564).
#drupal-contribute:
- Drupal- ,
? ( ). ,
.
, ,
. ( IRC
9.) IRC-
- , ,
. , ,
, .
, .

470

23.

, , ,
, , .
. ,
Drupal , :
. .
, , , ,
.
,

. , ,
, .

Drupal-
(, , ), ,
. 18
Drupal .
.
,
[Drupal],
, ?


31 , .
,
.
Drupal, ,
.
. Drupal
. , Drupal.
, ,
- Drupal.
Drupal API. Drupal
(Jeff Eaton) , ,
, includes.
, :
();
;
;
;
;
;
();
;
;
;
;
;

API?

471

;
;
;
;
XMLRPC;
AJAX;
Unicode ;
;
... .
(, includes/
graph.inc
), ,
. , Drupal
,
.
API,
. API- CTools VotingAPI.

API?
API ,
- .
-
, API .

, Drupal,
.
, API, , .

API UI
,
(UI), .

(API) .
.
db_insert(), db_update()
db_delete(), db_, drupal_write_record(). ,
, ,
,
. ,
. .
API-,
. ( , Drupal
.)
, API UI,
, .
Fields . Views
Views UI.

472

23.

API
,
, -. ,
, API-. DrupalCon DC
VotingAPI (drupal.org/project/votingapi).
,
.
, .
- , .
VotingAPI .
,
.
, . .
. , API
,
,
.
, API , ,
.

, ,
, .
, -, ,
. ,
,
, , .
, ,
, .


API
. .
Form Messages, ,
-.
,
.
, .


, Drupal
(, hook_menu() -
URL-), (, hook_views_default ()
, ).
.
Form Messages
. ,
, , , hook_default_views()

473

, .
Form Messages
( dgd7.org/strategy). ,
modulename.api.php,
.
,
, .
.
drupal_alter().
,
. drupal_alter() ,
.

drupal_alter()
,
. , ,
, ,
, ,
.

,
.
. ,
( ,
): ; API.
API-
,
, , .
API- : -
, . Drupal
; .
Unix-. (Doug Mcllroy),
Unix Unix-, : ,
- , . ,
.

,
.



, . -
, , , Views. (
, Drupal-
Field API.)

.
.

474

23.

. ,
.
,
. ,
( ), ,
, .
, Menu Block, .
hook_help(), ,
:
if ($path == 'admin/structure/menu' && module_exists('block')) {
return '<p>' . t('Each menu has a corresponding block that is managed
on the <a href="@blocks">Blocks administration page</a>.>
array('^blocks' => url('admin/structure/block'))) . '</p>';

}
module_exists(' block ').
Block Menu . Help,
.
.

Help? Block?
, .
, Block ,
. Panels (
, ). Context. Panels
Context Drupal.
. ,
.

Drupal
.
, ,
Views. PathAuto
, , Drush-.
Drupal, hook_help().
, , ,
.
Advanced Help, ;
Advanced Help.


.
Drupal, , ,
. Drush 2 25.
drush siteinstall (si). ,
cd -/workspace
cd formmsgs
drush dl drupal --drupal-project-rename=formmsgs
drush si --db-url=mysql://root:rootpass@localhost/formmsgs

475

.
, , ,
. .
, ,
( ).
, formmsgs. ,
.
. form_messages hook_help(),
, , hook_messages_help(),
- .

drush site-install
, (user ID 1)
admin password.

.
Drupal dgd7.org/sh.

; sites/default
. ( modules, -
mkdir , formmsgs.) Git :
mkdir - sites/default/modules/formmsgs
cd sites/default/modules/formmsgs
git init

Git
, git add . ( ,
, , )
git commit.


.info , Unique fields,
(, ,
, ):
drush dl unique_field
cp ../../../all/modules/unique_field/unique_field.info formmsgs.info
gvim formmsgs.info

. Info- ,
. , . ,
. .module ,
,
name = form messages
description = "[formmsgs] Provides immediate, in-form validation."
core = 7.x

,
.

476

23.

Drupal.org
.info, ( 23.1)
.
drupal.org/node/add/project-project.
23.1. Drupal.org
git add .
git commit -m "Initial commit for AJAX form messages module;
the .info file."
git remote add origin mlncn@git.drupal.org:sandbox/mlncn/910490.git
git push origin master
git checkout -b 7.x-l.x
git push origin 7.x-l.x

, 23.1, Git instructions .


drupal.org/node/910490/git-instructions Form Messages,
(
910490).

, .
, ,
Views, Token, Administration Menu, Date, Webform, Devel, Voting API (
24 Commerce, Apache Solr, 29).
,
. ,
Form Messages.
dgd7.org/strategy.


, API, ? ,
,
. , API- , .
. API Form Messages
, .
, .
, ,
- .
, Form Messages ,
. , ,
API-
, , , API .
?
, , ?
?
( )
AJAX-?
, ,
API- ( , ,
). ,

477

, .
, API.

API
AJAX- Form Messages, , : .
, - ?.
API ,
( UI-) .
( .)
, ,
.

,
.
, AJAX- Form Messages.
API ,
(, ),
API- .
, ,
.


, , , ,
, , ,
API. API .
, ,
, ,
.
AJAX- Form Messages
,
.
. , API,
, .
, ,
.
, , .
, AJAX-,
. .
?
, , ,
( ,
, ),
. , ,
date_validate() (. api.drupal.org/date_validate) (
$form), , .

FormAPI,
(), , .

478

23.


AJAX- Form Messages
.
, , ,
, , .
.
, .
16, ,
.
/**
* hook_form_alter().

*/

function formmsgs_form_alter(&$form, &$form_state, $form_id) {


debug($form, $form_id, TRUE);

>
debug(),
, .
TRUE. debug() ,
.

debug() ,
, Configuration Logging and
errors Development (admin/config/development/logging). ,
settings.php $conf['error_lever] = 2;.
, settings.php ,
dgd7.org/err.
23.2. node/add/article
'title' =>
array (
'#type' => 'textfield',
*#title' => 'Title',
'#required' => true,
'#default_value' => NULL,
'#maxlength' => 255,
'#weight' => -5,

b
. t i t l e 23.2
$form,
. title .
( ) (title) ,
. ,
.
. (
.)
, ,
, ,
.
form_set_error() (api.drupal.org/form_set_error). ,
form_errori() (api.drupal.org/form_error). ,
, .

479

, .
, ,
.

,
JavaScript. AJAX .
:
JavaScript- , .
AJAX. ,
hook_form_alter(). , pass
#type password_confirm'. password_confirm
form_process_password_confirm() includes/form.inc.
password-field password-confirm .
modules/user/user.js. ,
, .


, ,
, Drupal-.
:
.
, Drupal
, Form API api.drupal.org/api/drupal/developer--topics-forms_api_reference.html/7#element_vaiidate ( URL-
dgd7.org/strategy).
AJAX- hook_form_alter().
Drupal element_validate ( grep -nHR
'element^validate' modules/ Drupal) .
77 modules/image/image.admin.inc element_validate
image_style_name_validate().
(admin/config/
media/image-styles/add) debug($form, $form_id);
hook_form_alter() .
.
'name' =>
array (
'#type' => 'textfield',
'#size' => '64',
'#title' => 'Style name',
'#default_value' => '
'#description' => 'The name is used in URLs for generated images.
Use only lowercase alphanumeric characters, underscores (_),
and hyphens (-).',
'#element_validate' =>
array (
0 => 'image_style_name_validate',

'required' => true,

b
AJAX- Form Messages
JavaScript-, .
dgd7.org/strategy.

480

23.

JavaScript- / CSS-,
, ,
hook_library(). #attached[,library']
drupal_add_library().
api.drupal.org/hook_library drupal.org/node/756722.

AJAX-,
Examples for Developers (drupal.org/project/examples),
hook_form_alter() AJAX-.
Form API, AJAX, ,
,
api.jquery.com/category/events, ,
keyup():
/**
* hook_form_alter().

*/
function formmsgs_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'image_style_add_form') {
$form['name'][#ajax'] = array(
'callback' => 'formmsgs_image_style_name',
'event' => '',
'wrapper' => 'formmsgs-image-style-name' ,

);

$form['name']['#suffix'] =
'<div id="formmsgs-image-style-name">Default message.</div>';

}
}
, ,
, ,
, .
, AJAX- ,
- .
/**
* .

*/
function formmsgs_image_style_name() {
return 'Change- presto. ';

}
! Default message Change- presto
, Name .

replace ,
, -,
wrapper. , , div
. , -
, AJAX . AJAX-,
Examples (drupal.org/project/examples) api.drupal.org/
api/group/ajax_commands/7, .

, .
, ,
:

481

function formmsgs_image_style_name($form> $form_state) {


die(va r_expo rt($form,TRUE));

>
, AJAX.
dgd7.org/273;
( ) name.
function formmsgs_image_style_name($form, $form_state) {
image_style_name_validate($form[name]);
$message = form_get_error($form['name']);
if (!$message) {
$message = "Default message.";

$commands = array();
$commands[] = ajax_command_html('#formmsgs-image-style-name, $message);
return array('#type' => 'ajax', 'commands' => $commands);

>
Default message Please only use lowercase
alphanumeric characters, underscores (_), and hyphens (-) for style names,
. 23.1.
S ty le n a m e *_________

____

The nam e is used in URLs for generated im ages. Use only lowercase alphanumeric characters, underscores (J , and hyphens (-).

Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.

Create new style

. 23.1. , AJAX

,
AJAX- html,
. , ,
.
Please only use
lowercase alphanumeric..., . , ,
. , form form_state
, ,
. , ,
(
, )
JQuery, AJAX-.
., . ,
- , ,
, ( throbber), ,
# jax ( ,
#path callback).
form_get_error (),
. , , !
API, .

482

23.



, , ,
. API,
, .
, ,
UI.
, , AJAX-
Form Messages. ,
.
,
.
,
, .
:
,
.
, .
, ,
.
, /. ,
.
. ,
,
.
.
, . ,
,
.
. : ,
.
, . .
, , .
,
.
, ,
(, FALSE).
,
, .
, , API AJAX- Form
Messages .
, .
, , ,
. , ,
, , Form Messages .
, .
, .

483

Form Messages.
.
, .
, :
.
, ,
-, - .

UI
.
.


UI .
. . ,
. .
Drupal
. ,
, : . , Drupal
.
, , , , ,
.
,
, , .
, , , CTools.
, , Drupal.
(Wolfgang Ziegler) , Entity API
.
drupal.org/node/1021526. ( ,
-, .)
,
.
, , ! , ,
, (
), , .
: ,
, . -,

? , , ,
, Drupal .
JSON,
.
PH P- , CTools
JSON. Profile2 Message,
Entity API, , JSON.
, . ,
, Entity API ,
. ,
Entity API, .

484

23.

, e n tity F ie ld Q u e ry ( ),
Drupal 7.
E ntityFieldQ uery (api.drupal.org/EntityFieldQuery) Views
.
. dgd7.org/entities.

.
. Drupal
: Entity API, ,
, CTools.
, . CTools
. , ,
, Views Panels.



Drupal-, ,
.
Drupal 7,
. , ,
, , .
, .


, , . ,
. ,
, .
Commerce (. 24) ,
. ,
, , ,
.


h o o k _ e n tity _ in fo ( ). ,
, Examples,
drupal.org/project/examples api.drupal.org/hook_entity_info;
dgd7.org/entities.
AJAX- Form Messages
( , ?),
Entity API (drupal.org/project/entity), ,
. ,
, ,
, Entity API. ,
, Entity API
drupal.org/node/1021526.
, Entity API
, .

485

, ,
,
name = AJAX form messages API
description = "[formmsgs] Provides immediate, in-form notice
of validation requirements."
package = Form Messages
core = 7.x
dependencies[] = entity

, .info.
API-, ,
, ,
( , ), API
. AJAX Form
Messages (admin/modules).
.install.
, .

(, 23.3, ),
, .
2 3 .3 . hook_schema() formmsgs.install Form Messages
<?php

/**
* @file
* DB, Form Messages.

* .

*/
/**
* hook_schema().

.*/

function formmsgs_schema() {
$schema = array();
$schema['formmsgs'] = array(
description' => 'Stores information about all formmsgs entities.',
'fields => array(
'fmid' => array(
type => 'serial',
'not.null' => TRUE,
'description' => 'Primary Key: Unique form message ID.',

'name' => array(


'description' => 'The machine-readable name of the form message.',
type => 'varchar',
length => 32,
'not null => TRUE,

),

'label' => array(


'description' => 'The human-readable name of this form message.',
'type' => 'varchar,
'length' => 128,
'not null' => TRUE,
'default' => ",

'status' => array(

description' => 'Boolean indicating whether the for*

486

23.

23.3 ()
message is active.',
'type' => 'int',
size' => 'tiny',
'not null' => TRUE,
'default' => 1,

),

) + entity_exportable_schema_fields(),
'primary key' => array('fmid'),
'unique keys' => array(
'name' => array('name'),

),
);

return $schema;

>
+ entity_exportable_schema_fields(),
EntityAPI.
. ( )
. Entity API
, .

hook_entity_info(). .
, hook_schema() (
.install).
node_entity_info() modules/node/node.module.
Entity API drupal.org/node/878804.
Entity API controller,
, exportable TRUE ( 23.4).
23.4. New Form Message formmsgs.module
<?php

/**

* @file
* .

*/
/**
* hook_entity_info().

*/
function formmsgs_entity_info() {
$return = array(
'formmsgs' => array(
'label' => t('Form message'),
'controller class' => 'EntityAPIController',
'entity class' => 'Formmsgs',
'base table' => 'formmsgs',
'fieldable' => TRUE,
'exportable' => TRUE,
'entity keys' => array(
'id' => 'fmid',
'name' => 'name',
'label' => 'label',

'access callback' => 'formmsgs_entity_access',


'module' => 'formmsgs',
'admin ui' => array(
'path' => 'admin/structure/formmsgs',

487

'file' => 'formmsgs.admin.inc',

'bundle keys' => array(


'bundle' => 'name',

),

'bundles' => array(


'formmsgs' => array(
'label' => t('Message'),

b
b

'view modes' => array(


'full' => array(
'label' => t('On form'),
'custom settings' => FALSE,

b
h
);

return $return;

}
' controller class' EntityAPIController,
EntityAPI.
' entity class'. Formmsgs.
, .
Field API
, ' f i e l d a b l e ' TRUE.
' e x p o r t a b le ' , Entity API.
' base table ' , hook_schema ().
' label' ' Form message',
' entity keys' ' label' ,
. (fmid)
(name) ' entity keys ' .
' name' ,
Entity API; .

, .
, , ,
formmsgs , ,
, Drupal .
, ,
Drupal.org. ( )
dgd7.org/entities.

Entity API , ,
, FormmsgsController, ,
Drupal, DrupalDefaultEntityController.
. ,
(, , ),
, .info files[].
, .
Entity API. EntityAPIController,
Drupal includes/entity.controller.inc.
DrupalDefaultEntityController .
, , EntityAPIController.

488

23.

' en tity c la s s ' Formmsgs


. , ,
formmsgs.info
f ile s [ ].
/**
* , .

*/

class Formmsgs extends Entity {


public $label;
public $status;
public function
construct($values = array()) {
parent::_construct($values, 'formmsgs');

}
>
Entity Entity API;
Entity.
label status, .


Entity API .
'access callback' hook_entity_info()
formmsgs_entity_access().
.
entity_metadata_comment_access() entity/modules/callbacks.inc.
/**
*
* formmsgs Entity API.

* (0TODO Entity API, hook_menu 'access


* arguments' user_access().

*/
function formmsgs_entity_access($op, $entity = NULL, $account = NULL) {
return user_access('administer formmsgs');

}
Entity API
. @TODO,
, ,
,
user_access(). ,
,
.

20 , ,
. ,
,
. 23.5.

489

23.5. hook_permission() System Module

/**
* hook_permission().

*/
function system_permission() {
return array(
'administer modules' => array(
'title' => t('Administer modules'),

'administer site configuration' => array(


'title' => t('Administer site configuration'),
'restrict access' => TRUE,

b
//

. . .

)J
}
' restrict access' => TRUE Drupal
( , )
Permissions : Warning: Give to trusted roles only; this permission has
security implications. ,
.
,
. Filter Filtered
Full HTML, , (fallback form at).
Filter, ,
. :
// .
// , ,
foreach (filter_formats() as $format) {
$permission = filter_permission_name($format);
if (!empty($permission)) {
//
// ,
// .
$format_name_replacement = user_access(
'administer filters') ? l($format->name,
'admin/config/content/formats/' . $format->format) :
drupal_placeholder($format->name);
$perms[$permission] = array(
'title' => t("Use the !text_format text format", array(
'!text_format' => $format_name_replacement,)),
'description' => drupal_placeholder(t('Warning: This permission may
have security implications depending on how the text format is
configured.')),

);
}
}

return $perms;

hook_permission() Filter:

,
. . user_access(),
!

490

23.

hook_permissions() Form messages


. ,
Unique Field.
/**
* hook_permission().

*/
function formmsgs_permission() {
return array(
'administer formmsgs' => array(
'title' => t('Administer form messages),
'description' => t('Allows administrators to configure errors
and warning messages.'),

'bypass formmsgs' => array(


'title' => t('Bypass form message errors'),
'description' => t('Allows users to ignore errors set through
form messages.'),

b
);
}


Entity API
, .
23.4 Form messages hook_entity_info()
admin
:
'admin ui' => array(
'path' => 'admin/structure/formmsgs',
'file' => 'formmsgs.admin.inc',

),
formmsgs.admin.inc ( 23.6).
Entity API ,
form. (
Entity API
,
. - .)
23.6. Form Messages Entities
, formmsgs.admin.inc
<?php

/**
* @file
* , .

*/
j **
* add/edit.

*
* , Entity API.

*/
function formmsgs_form($form, &$form_state, $formmsg, $op = 'edit') {
if ($op == 'clone') {

491

$formmsg->label .= ' (cloned)';


$formmsg->name .= '_clone';

$form['label'] = array(
'#title' => t('Label'),
'#type' => 'textfield',
'#default_value' => $formmsg->label,

);

// .
$form['name'] = array(
'#type' => 'machine_name',
'#default_value' => isset($formmsg->name) ? $formmsg->name : '',
'#disabled' => ($op === 'edit') ? TRUE : FALSE,
'#machine_name' => array(
'exists' => 'formmsgs_load_by_name',
'source' => array('label'),

#description' => t('A unique machine-readable name for this form


message. It can only contain lowercase letters, numbers, and
underscores.'),

);

$form['status'] = array(
'#type' => 'checkbox',
'#title' => t('Active'),
#default_value' => $formmsg->status,

);
field_attach_form('formmsgs', $formmsg, $form, $form_state);
$form['actions'] = array('#type' => 'actions');
$form[actions']['submit'] = array(
'#type' => 'submit',
'#valiie' => t('Save form message'),
'#weight' => 50,

);

return $form;

}
/**
* Form API formmsgs add/edit.

*/
function formmsgs_form_submit(&$form, &$form_state) {
$formmsg = entity_ui_form_submit_build_entity($form, $form_state);
// .
$formmsg->save();
$form_state['redirect'] = 'admin/structure/formmsgs';

}
form m sgs_form () f ie ld _ a t t a c h _ f o r m ( ),
,
Form message, .
.
, formmsgs_fc>rm_submit(),
.
Entity API, -> s a v e () .
Entity API ,
Form messages .

492

23.

, EntityAPI.
23.7 formmsgs.module,
, .
Profile2 (
fago, Entity API). ,
formmsgs_load_by_name() p ro f ile 2 _ g e t_ ty p e s ( ) .
Entity API
.
node_load() node_load_
m ultiple (). , , , formmsgs_load()
formmsgs_load_multiple(). :
. API
(Larry Garfield) (data.agaric.com/
aphorisms-api-design) DrupalCon ( ,
- ).
2 3 .7 . ,

Entity API, , formmsgs.module

/**

* formmsg.

* ,
* .

*
*
*
*
*

(ram $name
, .
@return $formmsgs
$name .

*/

function formmsgs_load_by_name($name = NULL) {


$formmsgs = entity__load('formmsgs' , isset($name) ? array($name) : FALSE);
return isset($name) ? reset($formmsgs) : $formmsgs;

}
/**
* .

*
*
*
*
*
*
*
*
*

@param $fmid
.
@param $reset
,
.
^return
$formmsg FALSE,
.

* @see formmsgs_load_multiple()

*/
function formmsgs_load($fmid, $reset = FALSE) {
$formmsg = formmsgs_load_multiple(array($fmid), array(), $reset);
return reset($formmsg);

>
/**
* .

*
*
*
*
*
*
*
*
*

493

@param $fmids
.
@param $conditions
, {formmsgs}.
@param $reset
,
.
(Sreturn
, fmid.

* @see entity_load()
* @see formmsgs_load()

*/
function formmsgs_load_multiple(
$fmids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('formmsgs', $fmids, $conditions, $reset);

}
, , entity_load()
Drupal (. api.drupal.org/entity_load), EntityAPIController
.
, ,
Form message, , .
.


(,
) . ,
.
( ,
) AJAX- Form Messages ,
. Form Messages ,
,
.


,
. Node
node_add_body_field( ), body
. modules/node/node.module api.drupal.org/
node_add_body_field. Taxonomy,
283 profiles/standard/standard.profile.
. ,
, Text , Field
modules/field/modules/text.module:
fu n c tio n t e x t _ f i e l d _ i n f o ( ) {
re tu rn a rra y (

'text' => array(


'label' => t('Text'),
'description' => t('This field stores varchar text in the database.'),
'settings' => array('max_length' => 255),
'instance_settings' => array('text_processing => 0),

&

494

23.

'default_widget' => 'text_textfield',


'default_formatter' => 'text_default',

)>

text_long' => array(


label' => t('Long text'),
'description' => t('This field stores long text in the database.'),
'instance__settings' => array('text_processing' => 0),
'default_widget' => 'text_textarea',
'default_formatter' => 'text_default',

b
// ...
);
}
(max_length) 255 ,
text_long. 255 , ,
, .
50 (. drupal.org/node/1052248).
, .install.
: ( )
( ). hook_install():
/**
* hook_install().

*/
function formmsgs_install() {
// .
$field = array(
'field_name' => 'field_message',
'type' => 'text_long,
'entity_types' => array('formmsgs'),
'translatable' => TRUE,

);

$field = field_create_field($field);
// .
$instance = array(
'field_name' => 'field_message',
'entity_type' => 'formmsgs',
'label' => t('Message'),
'bundle' => 'formmsgs',
'description' => t('Message to show on error.'),
'widget' => array(
'type' => 'text_textarea',
'weight' => -5,

b
)J

field_create_instance($instance);

>

f ield_create_f ield ().
. ;
,
. .
.install
. .
AJAX- Form Messages
dgd7.org/strategy.

495

, - (
)
hook_update_N() hook_install().



...
.

.
, . ( ,
, .)
, , : .
;
, .
.
,
.
.

, .

,
.
.
. ,
. ,
.

,
, , .
Drupal- ,
, .
, ,
.
dgd7.org/strategy drupal.org/project/formmsgs.

VI.

24 - ,
Drupal 6 Drupal 7
Ubercart
.
,
, ,
.
25 Drush
,
. ,
Drush- Drush-.
26
,
,
, ,
.
27 Drupal,
.
28, , Drupal
. 27
- Drupal.
29 Solr,
.
Drupal -
- .
30

DefinitiveDrupal.org, 1 8.
31 Drupal
Drupal , .
Drupal .
,
Drupal.

24. Drupal Commerce


Drupal , .
Commerce Drupal 7. Drupal Commerce

Drupal 7, ,
API. Drupal Commerce,
, ,
.
, Drupal Commerce
. ,
Drupal 7.

Drupal Commerce
Drupal ,
.
,
-.
, , ,
.
Drupal 4.5
,
. Drupal Commerce .
Drupal , Views,
,
.
, ,
, Drupal 7, ,
, , Rules Views.
,
, . Drupal
Commerce Drupal,
.
Drupal,
-,
.


,

.
,
.
(User Interface, UI) , Product Product UI,
, , Cart Checkout.

Drupal Commerce

499

, :
.
,
.
Drupal 7
.
,
.
, ,
, .
, ,
.
,
, , . .
,
.
,
, .
,
,
.
, .
.

Drupal Commerce
, Drupal Commerce,
,
, drupalcommerce.org.
Drupal Commerce,
.
,
,
.
: Git- Git Hub
Drupal.org. ,
drupal.org/project/commerce modules
.
, Git-
,
Code Workflow (. drupalcommerce.org/development/workflow).

(Ryan Szrama), Drupal Commerce,


, .

drupalcommerce.org/development/workflow/repositories.

500

24. Drupal Commerce

Address Field (drupal.org/project/addressfield);

Chaos tools suite (drupal.org/project/ctools);

Entity API (drupal.org/project/entity);

Rules (drupal.org/project/rules);

Views (drupal.org/project/views).

,
. Drupal 7, ,
,
Commerce: Contextual links Field UI. ,
:

Address Field;

Entity CRUD API;

Entity Tokens;

Rules;

Rules UI;

Views;

Views UI;

Chaos tools, Views.

Administration Menu ,
Overlay Commerce UI.
drupal.org/project/admin_menu.

, .
,
:
Commerce/Commerce UI
, ,
Field API.
Price Price .
Product/Product UI p ro d u c t
.
Physical Product , .
Line Item/Line Item UI l i n e item , API
,
.
Product Reference ,
.

Product Pricing/Product Pricing UI Rules


.

API UI
.
Customer/Customer UI custom er p r o f i l e
,
,
.
Tax/Tax UI

Drupal Commerce

501

Order/Order UI order
.
Payment/Payment UI payment transaction

.
Checkout
, , .
Cart UI-, ,
.
,
. ,
Product Reference Line Item
, , hook_commerce_
line_item_info() Product Reference.
, .
, . , :
,
;
;
;
;
;
Rules, .

Drupal Commerce ,
Commerce Kickstart,
Drupal.
,
drupalcommerce.org/development/installation-profiles.

Commerce
Commerce API-,
Views Forms API.
Drupal Commerce
,
. Commerce
ISO 4217,
hook_commerce_currency_info_alter().
Commerce UI Management,
Store. UI-.
Configuration, Store,
Commerce. Currency settings,
. 24.1, Configuration.
, ,
, , .
, ,
, ,
, ,

502

24. Drupal Commerce


Field UI.

'Home * Adrrjtolsiratbn * Store. CoitftguratkHi

Default store currency


USD - umeti States Oonars - $

th e default store currency,will be used as' the default for all price fields.

ENASLED CURRENCIES

Save configuration

. 24.1. Currency settings ,


,

Price
Price , ,
, .
ISO 4217
, ,
. ,
. 24.2. , Price textfield,
, , Price with currency,
.
Price tex tfieid
USD

Price w ith currency


USD - $

. 24.2. Price

, Price , API c o m m e rc e _ p ric e _ c re a te _ in s ta n c e (). Drupal Commerce



. Product , ,
, , ,
:
/**
* .

*/
function commerce_product_configure_product_type($type) {
commerce_price_create_instance(
'purchase_price', 'commerce_product', $type, t('Price'));

}
c o m m e rc e _ p ric e _ c re a te _ in s ta n c e ()
, ,
.

Drupal Commerce

503

,
.
.
, , , .
, Field UI.
Price with currency,
, ,
.
, ,
, .
Views


Price
. ,

. Price
Product Pricing , Rules UI.
,
Drupal
,
. , ,
, ,
.
. , Price
,

.

Product

. ,
,
. Product Drupal 7
, ,
.
,
, .
hook_
entity_info(). Drupal 7
Drupal Commerce, ,
, .
,
.

,
Product UI. Products,
Store.

504

24. Drupal Commerce

. Product Types
,
, . 24.3.
PRODUCT TYPES

Home * Administration * Store * Products

4- Add product type

NAME
Product {.Machine name
A basic product type.

OPERATIONS
jjroduct)

edit

manage fields

manage display

deters

. 24.3. Product Types


Product UI ,
, ,
.
,
.
manage fields, . , Cart,
, Add to Cart ,
.
t-shirt,
:
1 . Add product type t-sh irt.
, ,
.
2. Save and add fields,
Manage Fields.
3. Add new field ,
Title Price. label S ize ,
s ize .
List (text).
Select list, , Save,
.
4. Allowed values ,
Size
, , .
, Save field settings.
5. , Size t-shirt
. Required field
Label, . ,
Number of values Size field settings 1,
Allowed values .
6. , Save settings.
Manage Fields (. 24.4).
, , .

Drupal Commerce

Products

MANAGE FIELDS

505

MANAGE DISPLAY

Home * Administration * Store Products * Product types

Show row weights

LABEL

NAME

FIELD

WIOCET

Product SKU

sku

Product module SKU form element

Titte

tftie

Product moduie tltie form element

4*

Size

field.size

list (text)

Select list

edit

delete

4*

Price

base_pnce

Price

Price with currency

edit

delete

i*

Status

status

Product module status form element

OPERATIONS

. 24.4. Manage Fields ,


, , Field UI



. Store Products.
Add a product,
. ,
, t-shirt,
, .
, ,
,
. Commerce Drupal ,
.
API
, .
Drupal Commerce
Ubercart Product.
,
,
.
Drupal Commerce
, ID
SKU.
.

SKU Stock Keeping Unit ( )


,
. SKU ,
, ,
, , .

API UI- .
.
Google Summer of Code 2010 Drupal,
Commerce Bulk Product Creation, drupal.

506

24. Drupal Commerce

.
SKU- .
,
.
, ,
, Product Reference. , ,
Drupal Commerce
.
,
. ,
SKU ,
. ,
.
, Drupal

. , Physical Product ,
, .
,
, ,
.
org/project/commerce_bpc.

Line Item
Drupal Commerce ,
. line item,
, ,
,
. ,
.
, , :
Label ();
Title ();
Display options ( );
Quantity ();
Unit price ( );
Total price ( ).
, , ,
hoo k_co m m erce_lin e_item _in fo( ).
Product Reference.
,
.
Line Item Info hooks Drupal Commerce Specification (. www.
drupalcommerce.org/specification).

(drupalcommerce.org/specification)
, API.

, Line Item,
lin e _ ite m _ id .

Drupal Commerce

507

, ,
,
# ja x Forms API (. 24.5). ,
Cart, API,
, ,
.
com m erce_cart_product_add() commerce_cart.module.
LINE ITEMS
REMOVE
1
G

Product j j

QTY

TITLE

SKU

Product Three

PROD-03

30.00

USD

560.00

Product One

PROD-Ol

i%

10.00

USD

S 10.00

PRICE

TOTAL

A d d lin e ite m

. 24.5. ,

Views
, . API
, .
Store, Configuration
Line item types.
. ,
,
.
h o o k_ co m m erc e_ lin e__ ite m _ in fo _alter().
Product
Reference Cart, Tax , h o o k _ c o m m e rc e _ ta x _ in fo ()
. .
.
Views .
, ,
.

Product Reference
Product Reference ,
,
. Add to Cart
. , Product Reference
,
. , ,
, Cart, Add
to Cart. , Views,
, .
.
, ,
Drupal Commerce. ,
,

508

24. Drupal Commerce

, .
.


:
1 . Structure Content types.
Add content type. P ro d uct d is p la y
.
2. Save and add fields,
Manage Fields.
3. Add new field Product,
product.
Product reference,
Autocomplete text field. Save,
.
4. Product types that can be referenced,
. , Save field settings.
5. , Product
Product display . Product display settings
Required box Label, Product display
. Number of values 1
Save settings Manage Fields.
6. Manage Display, ,
(Body Product) ,
(Product: Size Product: Price). size T-shirt,
.
Add to Cart, ,
. 24.6. .
Show row weights
LABEL

F fa o
*$*

Body

<> *|

Product

Default

zl

Visible j*j;

Product: Price

FORMAT

<HSddem>

Add So Cart fom j J

Hidden
4*

Product Size

Hidden

. 24.6.
, , Add to Cart

7. , ,
.
, ,
Store, Products
Product types.
,
.

Orupai Commerce

509

,
. Autocomplete text field
Node Edit, SKU- ,
, SKU .
Add to Cart,
, .

. .
, tshirt ,
. Drupal Commerce ,
,
, .
, Number of values
1 u n lim ite d .

SKU-. , Add to Cart,
, .

.
, ,
. ,
image ,

. ,

, ,
, - .
, ,
, .

Customer
Customer custom er p r o f i l e
. .
. custom er p r o f i l e
,
.
. , ,
, ,
.
.
.
, Billing information,
, Address Field,
.
,
.
, . -,
.
,

510

24. Drupal Commerce

, . -,
, -
, . -, ,
,
,
. -,
.
, .
,
.
hook_commerce_customer_prof i l e _
i n f o ( ). ,
, ,
. Customer
, .
o rd e r,
.

. , Store Customer
profiles, , ,
,
.
.

Order
order, API. order
,
.
, .
,
, , .
, ,
.

, , ,
. ,

.
.
, (order states)
. ID ,
, .
, , ,
, , .
, ,
.
, Store
Orders, ,
Configuration . ,

Drupal Commerce

511

,
, .
,
Drupal Commerce.
,
.
Views
,
, Views
Bulk Operations .

Payment
Payment payment transaction,
.
.
.
,
. Payment
,
, .
,
, ,
. payment transaction
, .
, , .
,
. .
Payment ,
Store Orders.
,
.
Payment
Method Example ,
, . 25.7.
VIEW

EDIT

PAYMENT

]
Home * A dm inistration Store O rd e rs

STATUS ,

Example

10/29/2010

payment

METHOD

Example
payment

A dd paym ent

REMOTE iD

RESULT MESSAGE

AMOUNT

OPERATIONS

s50,00 : view'
Total paid

Order balance

S50.00

$0.00

. 24.7. Payment ,
,

512

24. Drupal Commerce


Payment Method Example
.
, hook_commerce_payment_info()
,
. ,

. Payment
Info hooks Drupal Commerce Specification.
Payment ,
. Payment
Review checkout ,
, .
, ,
, ,
. ,
.
Rules.
, .
. , ,
, , .
.
Example payment,
.
. 24.8.
Events
EVENT

OPERATIONS

Select available payment methods for an order

delete

4* Add event

C onditions

Show row w eights

ELEMENTS

OPERATIONS

User has role<s)


Parameter: User: fsite:curr*nt~user], Rcfes; 3
+ Add condition

#* Add or

edit delete

+ Add and

A ctions

Show row w eights

ELEMENTS

OPERATIONS

Enable payment method' Example payment


Parameter. Order {order]
4 Add action

edit, delete

4- Add loop

. 24.8.
1.

Store Configuration
Payment methods.

Drupal Commerce

513

2. Disabled payment rules Enable Example


payment , .
3. Edit ,
. , ,
. Actions Enable
payment method: Example payment. Edit ,
. .
4. Add condition
Conditions. User has role(s)
Continue.
5. , Rules
. Data selector s i t e : c u rre n t-u s e r.
Rules
. Roles Administrator
Save.
6. . 24.8.
Example payment.
,
. Rules,
.
, ,
, .

Drupal Commerce,
, , Drupal.org.

Checkout
,
, .
, ,
.
,
, ,
, .
,
.

,
. , ,
.
.
, .

,
. .
,
, .
.

514

24. Drupal Commerce

, Checkout Payment,
:
Checkout .
Review order .
Payment ; ,
.
Checkout complete ,
.
.
, , .
, . 24.9,
(. Checkout Info hooks Drupal
Commerce Specification).
CHECKOUT FORM

Checkout settings
Home * Administration' Store Configuration * Checkout settings

Show row weights

CHECKOUT PANE

OPERATIONS

Checkout
4

Shopping cart contents

configure

4*

Billing information

configure

Review order
+J*

Review

configure

4*

Payment

configure

Payment
Off-site payment redirect

configure

Checkout complete

configure

Comptetion message

Disabled
No disabled p anes.

Save configuration

Reset to defaults

. 24.9. ,

Checkout Cart,
, .
URL- Cart checkout/#.

URL-, URL.
Drupal
.

Drupal Commerce

515

,
. Drupal
.
,
.

Cart
Cart ,
, .
, .
, , ,
Cart
. , , , Checkout
Review .
.
, . 24.10.
,
.
Views. ,
. ,
Views .
Shopping cart
1 Product One

$10.00

1*

$20.00

Product Two

2 items

Total: $ 30.00

. 24.10. , ,
Views

API Cart ,
Add to Cart.
,
.
,
; ,
.
.
#ajax Forms API,
.


, ,
Drupal Commerce,
. ,
,

.

516

24. Drupal Commerce

. 24.1,24.2 24.3
Drupal Commerce. , ,
.
2 4 .1 . Drupal Commerce

ID

Customer
profile

commerce_customer_
profile

profilejd

Line item

commercejinejtem

line_item_id

Order

commerce_order

orderjd

Payment
transaction
Product

commerce_payment_
transaction
commerce_product

transaction_id

, ,


,

API
, UI
,
, UI

productjd

2 4 .2 . Drupal Commerce

Customer profile reference


Line item reference
Price

Customer profile manager


Line item manager
Price text field

Customer profile display


Line item View

Price with currency

Raw amount

Formatted amount
Product reference

Autocomplete text field

Select list
Check boxes/radio buttons

Add to Cart form

SKU
Title
2 4 .3 . ,

Canceled
Shopping cart
Checkout
Checkout: Review (functions as cart)

Canceled
Shopping cart
Checkout: Checkout (, )

Checkout: Payment
Checkout: Complete
Pending
Processing (
)
Completed

Pending ( )

Completed ( )

Drupal Commerce

517

Drupal Commerce
, , ,

. , , , ,
Drupal Commerce, ,
.
: , .
, ,
.
, ,
.
Drupal,
.
, , ,
.
,
,
.
, ,
Drupal.
Drupal ;
, ,
,
. ,
, ,
. ,
: ,
Secure Pages SSL-.
,
Drupal Commerce ,
. Drupal Commerce
,
. Drupal,
Drupal.org.
Drupal Commerce :

.
, .
, .
.
.
.

Features ,
. ,
Views, Rules
Commerce .

518

24. Drupal Commerce

, .

, .


Drupal Commerce , .
, Drupal Commerce
Ubercart.
Ubercart, ,
.
,
Drupal 7 .
Commerce Ubercart:
,
.
,
.

Drupal 7 .

Drupal.
,
Features, , ,
.
Ubercart Drupal Commerce.

.
, IRC,
, .

drupalcommerce.org, .



, . -, .
(API UI).
,
, ,
,
.
, ,
, , .
,
, API ,
UI, .
, Cart Checkout,

519

-, ,

.

Drupal 6, Views
Rules . Drupal 7 : ,
Field Field UI.

, ,
, ,
, .
Drupal Commerce
,

. , , ,
.
, ,

.
Payment
, .

. Payment

. , ,
API ,
Drupal Commerce.
,
, ,
Drupal
. .
, ,
,
UI. , ,
,
,
.


Drupal Commerce ,
, ,
.
, ,
. ,
, drupalcommerce.org/
development/standards, .
, Drupal
, .
:

520

24. Drupal Commerce

,
Drupal-.
.
.info .
,
- .
Testing Drupal.
API .
.
.
.
API
.
.
.

Drupal 7
,
Drupal 7,
, .
Views.
, Rules ,
- , .
Drupal 7
, ,
Drupal Commerce.


Drupal 7 , .
,
, , , Content Construction Kit Drupal 6.
, .
,
,
.
product
Drupal Commerce ,

. ,
Drupal
, Drupal Commerce product.
, ,
, Add to Cart.
product Product 24.1.

Drupal 7

521

24.1. Product

/**
* hook_entity_info().

*/

function commerce_product_entity_info() {
$return = array(
'commerce_product' => array(
'label' => t('Product'),
'controller class' => CommerceProductEntityController',
'base table' => 'commerce_product',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'product_id',
'bundle' => 'type',

'bundle keys' => array(


'bundle' => 'type',

),

'bundles' => array(),


'load hook' => 'commerce_product_load',
'view modes' => array(

)/

foreach (commerce_product_type_get_name() as $type => $name) {


$return['commerce_product']['bundles'][$type] = array(
'label' => $name,

);
}

return $return;

}
, entity ,
, CommerceProductEntityController, CRUD-
, .
hook_entity_info_alter(),
. ,
, Views.
,
,
Rules product. foreach
product commerce_product_type_get_name(). API, hook_commerce_product__info()
, .
order
order ,
order.
,
, .
, ,
, .
,
, 24.2.

522

24. Drupal Commerce

24.2.

/**

* hook_entity_info().

*/
function commerce_order_entity_info() {
$return = array(
commerce_order' => array(
label' => t('Order'),
controller class' => 'CommerceOrcderEntityController',
base table' => 'commerce_order',
revision table' => 'commerce_order_revision',
'fieldable => TRUE,
'entity keys => array(
'id' => order_id',
'bundle' => 'type',
'revision' => 'revision_id',

'bundle keys' => array(


'bundle' => 'type',

'bundles' => array(


'commerce_order' => array(
'label' => t('Order'),

),

'load hook' => 'commerce_order_load',


'view modes' => array(

),
b
);

return $return;

}
, bundles .
- ,
hook_entity_info_alter().
Order
API .
,
, order.
, , .
controller ,

, Drupal . save
,
Field Attach .
.
.
drupalcommerce.org/specification/entities
.


, (

Drupal 7

523

) Add to Cart
. - Drupal 6,
.
drupalcommerce.org/specification/fields
.

Forms API
, Forms .
#ajax
Forms API
# ja x .

JavaScript-.

.
# a ja x .
Customer Address Field,
, , ,
.
, # a ja x
. Payment,
.
commerce_payment.checkout_pane.inc.
/ / .

$pane_form['payment_method'] = array(
'#type => 'radios',
'#options' => $options,
'#ajax' => array(
'callback' => 'commerce_payment_pane_checkout_form_details_refresh',
wrapper => payment-details',

),
)J


, DOM-,
, HTML ID.
JavaScript. .
Submit.

Forms API, ,
, Drupal
.
,
.
. ,
URL UI .
. ,
commerce_product.forms.inc:

524

24. Drupal Commerce

function commerce_product_product_form($form> &$form_state, $product) {


// .
$form_state[build_info']['files]['form'] = drupal_get_path(
'module'j commerce_product')
. '/includes/commerce_product.forms.inc';

>

Forms API, Drupal 7,


Drupal Commerce. ,
. ,
, ,
JavaScript. ,

API UI.


Drupal Commerce Drupal 7 ,

.
Views, Rules .
Views 3
, UI-
. , ,
, ,
Views.
Views 3.
, Payment
.

.
Rules. Entity API
Rules 2,
. Rules
,
. Rules
UI .

.
Address Field, Customer,
. ,
,
. xNAL
. ,

.

525

Drupal Commerce , ,
.
(drupalcommerce.org)
(drupal.org/project/issues/commerce),
, , ,
. IRC-
#drupalcommerce irc.freenode.net. ,
Drupal Commerce.

25. Drush

Drush Drupal, ,
Drupal, .
, ,
Drupal.
Drupal
(Graphical Users Interface, GUI), ,
-.
,
.

, ,
GUI. Drupal (
),
.
.
, ,
, ; -
Drush, - . Drush
.
Drupal-. Drush
, ,
.
Drush. , Drush ,
. . , Drush
Drupal,
Drupal API. Drush
,
Drupal. , ,
, Drupal.
Drush ;
Drupal
Drush .
, ,
. Drush
.
,
Drush . , , ,
Drush .
, Drush http://drupal.org/project/drush,
README.txt
.
. , :
Drush,
Drupal, ,
;

Drush

527

Drupal
, Drush;
Drupal ;
Drush, ;
Drush
;
Drush ,

;
Drush ;
Drush .

Drupal. .

Drush
Drush Drupal 5-7, MySQL,
Postgres SQLite. Drupal
, . ,
, ,
. , Drush
, Drupal.
Drush
, .

Drush-, siteinstall. :
$ mkdir dgd7
$ cd dgd7
$ drush dl drupal --drupal-project-rename=web -y
Project drupal (7.0) downloaded to dgd7/web.
Project drupal contains:
- 3 profiles: minimal, standard, testing
- 4 themes: seven, bartik, garland, stark
- 47 modules: node, trigger, system, statistics, simpletest,
php, poll, contextual, shortcut, field_ui, tracker, contact,
path, profile, help, overlay, aggregator, toolbar, image,
update, locale, translation, menu, blog, file, comment,
dashboard, syslog, user, book, filter, dblog, taxonomy,
search, block, rdf, forum, color, number, options, text,
list, field_sql_storage, field, openid,
drupal_system_listing_incompatible_test,
drupal_system_listing_compatible_test
$ cd web
$ cp sites/default/default.settings.php
sites/default/settings.php
$ chmod -R o+w sites/default
$ drush site-install --db-url=
pgsql://www-data:yoursqlpw@localhost/dgd7db --accountname=
admin --account-pass=secretsecret -y

528

25. Drush

Drupal
; , Drush- .

Drupal Drush-
Drush ,
Drush Drupal, .
, Drush,
Drush- c o re -s ta tu s. Drush,
25.1.
2 5 .1 . Drush- core-status Drush
$ drush c o re -sta tu s

configuration : /etc/php5/cli/php.ini
Drush version : 4.1
Drush configuration :
Drush alias files :

, Drush 4.1,
. php.ini.
, Drush ,
Drupal. Drush,
. . ,
. settings.php ( 25.2).
2 5 .2 . Drush- core-status Sites dgd7.org
$ cd d g d 7 /w e b /s ite s /d e fa u lt/

$ drush core-status
Drupal version
Site URI
Database driver
Database hostname
Database username
Database name
Database
Drupal bootstrap
Drupal user
Default theme
Administration theme
PHP configuration
Drush version
Drush configuration
Drush alias files
Drupal root
Site path
File directory path

7.0
http://default
Pgsql

localhost
www-data
dgd7devdb
Connected
Successful
Anonymous
bartik
seven
/etc/php5/cli/php.ini
4.1

/srv/www/dgd7/web
sites/default
sites/default/files

c o re -s ta tu s
. Drush-, Sites,
, Drush-.

Drush- (bootstrapping),
Drupal.
, , Drush- core-status
, Drush . ,
Drush , .

Drush

529

Drush . ,
25.3, Drupal.
2 5 .3 . cache-clear
$ drush cach e-clear

Enter
[0] :
[1] :
[2] :
[3] :
[4] :

a number to choose which cache to clear.


Cancel
all
theme
menu
css+js

1
'all' cache was cleared

Drush, , ,
- .
. ca ch e-c le ar a l l , .
, Drush Drupal;
, ,
Drupal, , ,
, , Drupal, ,
,
. . . . Drush !
, Drush- help,
. 25.1. (
).
, , .
Drush- ,
.
Drupal
. , Drush
. , - -root --uri
Drupal URI- Drupal sites:
$ drush --root=/srv/www/dgd7.org/web --uri=dgd7.org core-status "Site URI"
Site URI : dgd7.org

URI-,
. ,
settings.php URI- (, - - u r i = d e f a u l t ) .
, , 25.2
URI-, Drush Drupal.
, S it e URI . , URI-
. , ,
URL- HTTP- ;
URI-.
, - -root -uri,
. Drupal URI-
(#):
$ drush /srv/www/dgd7.org/web#dgd7.org core-status "Site URI"
Site URI : dgd7.org

, .
,
Drush. Drush :

530

25. Drush

,
Drupal,
. .
(drushrc.php)

(aliases.drushrc.php)

Dursh-

cache-clear ()

field-clone

field-create
field-delete

. URL

field-lnfo

field-update

URL-
-


Drupal

-11 ()

,
Drush
core-cron (cron)


core-rsync (rsync) Rsync
Drupal
SSH
-status

(status,st)
Drupal
core-toplc (topic)

module/
dru pal-directory
(dd)
theme
help
.

'drush help help'
Image-flush


php-eval
php-
(eval ev)
Drupal ( )
php-script (scr)
- ()
search-lndex

search-relndex

search-status

self-update
(selfupdate)
slte-allas (sa)

Drush ,




Drupal /
/,

site-lnstall (si)

site-upgrade
(sup)
test-clean
test-run
updatedb (updb)


( )
pm-download (dl) DrupaLorg

pm-enable ()


( )

pm-1nfo (pml)


( )
pm-llst (pml)
(
)
pm-refresh (rf)

pm-releasenotes
(rln)

pm-releases (rl)

pm-unlnstall

pm-update (up)

Drupal
( pm - updatecode +updatedb)
Drupal

pm-updatecode
()

SQL-
sql-cli (sqlc)
sql-connect


SQL, Drupal
DB

Drupal
( Drupal 6 Drupal 7)

sql-drop

sql-dump

Drupal SQL
mysqldump

.
uri

(
update.php)

vaiiable-delete

(vdel)
variable-get (vget)

variable-set (vset)
version


pm-dlsable (dls)

Drush

watchdog-delete
(wd-del wd-delete)
watchdog-llst

(wd-llst)
.
,

watchdog-show

(wd-show, ws)

sql-query (sqlq)
sql-sync


user-add-role

(urol)

user-block (ublk)

user-cancel (ucan)
user-create (ucrt)
user-lnformation
(ulnf)

()

user-login (uli)


(
- 1 )
user-password
(upwd)

user-remove-role
(urrol)

user-unblock
()
(uublk)

. 2 5 .1 . Drush-

Drush

531

Drush (aliases.drushrc.php)
Drupal ,
Drush .
drushrc.php; , aliases.drushrc.php,
, drushrc.php.
, Drush
; ,
, , .
aliases.drushrc.php.
example examples; Drush:
$ examples/example.aliases.drushrc.php $HOME/.drush/aliases.drushrc.php

example.aliases.drushrc.php ,
:
Aliases are commonly used to define short names for local or remote Drupal
installations; however, an alias is really nothing more than a collection of options.
A canonical alias named "dev" that points to a local Drupal site named "dev.
mydrupalsite.com" looks like this:
$aliases['dev'] = array(
'root' => /path/to/drupal1,
'uri' => 'dev.mydrupalsite.com',
)J

aliases.drushrc.php, root
, Drupal. uri URI-
.
. - - root - -uri
, 25.4.
2 5 .4 .
$ drush @dev core-status
7.0
Drupal version
http://dgd7.org
Site URI
Database driver
Pgsql
localhost
Database hostname
Database username
www-data
Database name
dgd7devdb
Connected
Database
Successful
Drupal bootstrap
Anonymous
Drupal user
Default theme
bartik
Administration theme
seven
PHP configuration
/etc/php5/cli/php.ini
4.1
Drush version
Drush configuration
/home/user/.drush/drushrc.php
Drush alias files
/home/user/.drush/aliases.drushrc.php
Drupal root
/srv/www/dgd7/install/dgd7/web
Site path
sites/default
File directory path
sites/default/files

@dev . .

Drupal,
, . ,

532

25. Drush

Drush,
.

Drush
Drush Drupal;
, drush core-cli.
bash.
Drush bash. core-cli
bash-, Drush. bash
, Drush.
exit Ctrl+D.
Drush , .
bash- Drush-,
drush. ,
, bash,
Drupal. .
core-cli Drush
. . 25.1
Drupal;
, core-cli
Drush-, ,
bash.
2 5 .1 . Drupal
Drush core-cli

Bash

$ drush @site1 core-cli

$ drush @site1 pm-download og

@site1> dl og

$ drush @site1 pm-enable og

@site1> en og

$ cd drush drupal-directory @site2

@site1> cd @site2

$ drush @site2 pm-download devel coder

@site2> dl devel coder

$ drush @site2 pm-enable devel coder

@site2> en devel coder

$ cd drush dru pal-directory @site2:%devel

@site2> cd %devel
@site2> use
_$______________

, , Drush
bash, cd use
. cd
;
Drupal, .
, Drush; %modulename
cd, ,
. use cd, . -,
; ,
Drush-. -, ;
, @remotealias, Drush-
SSH.
/ SSH-. ,
Drush.

Drush

533

c o r e - c li
Drush. Drush-
c o r e - c li - - pipe; bash-,
Drush, .
, bash ,
c o r e - c l i bash.
bash- ;
.bashrc .profile SHOME. Linux
Debian, Ubuntu, .bash_aliases ( $)
, .
Drush.
$ drush core-cli --pipe > $HOME/.bash_aliases
$ source $HOME/.bash_aliases

source bash-
, .
bash-, , source
( ).

;
Drush , - .
. help.
Drush- help, bash help! ,
bash ,
builtin help. status.
; Linux- Drush-.
use @alias Drush Ha@alias>, ,
Drush- ,
. status, Drush.
bash use .
, Drush, , Drush-
, .
Drush-
, .
bash; .

Drush
Drupal ,
. ,
.
update status
, . Drush
. ,
.
, .
, , ;
.
, .

534

25. Drush

,
. ;
, ,
.
, .
, ,
. - - s e le c t pm-download
log in to b o g g an ; - - a l l , Drush
( 25.5).
25.5.
$ drush @dev pm-download logintoboggan --select --all
Choose one of the available releases:
Cancel
[ 0]
7.x-l.x-dev
2011-Dan-06
- Development
[ 1]
7.X-1.0
2011-Jan-06
- Supported, Recommended
[ 2]
7.x-1.0-alpha3
2010-Aug-10
[3 ]
7.x-1.0-alpha2
2009-Oct-25
[4 ]
7.x-1.0-alphal
2009-Oct-21
[5 ]
4
Project logintoboggan (7.x-1.0-alpha2) downloaded to
/srv/www/dgd7/web/sites/all/modules/logintoboggan.
$ drush @dev pm-enable logintoboggan
The following extensions will be enabled: logintoboggan
Do you really want to continue? (y/n):
logintoboggan was enabled successfully.

alpha2; pm-updatecode
( 25.6).
2 5.6. Drupal pm-updatecode
$ drush @dev pm-updatecode
Refreshing update status information ...
Done.
Update information last refreshed: Sat, 01/15/2011 - 19:57
Update status information on all installed and enabled Drupal projects:
Name Installed version Proposed version Status
Drupal core 7.0 7.0 Up to date
LoginToboggan 7.x-1.0-alpha2 7.X-1.0 Update available
Code updates will be made to the following projects: LoginToboggan [logintoboggan7.X-1.0]
Note: A backup of your project will be stored to backups directory if it is not managed
by a supported version control system.
Note: If you have made any modifications to any file that belongs to one of these
projects, you will have to migrate those modifications after updating.
Do you really want to continue with the update process? (y/n):
Project logintoboggan was updated successfully.
Installed version is now 7.X-1.0.
Backups were saved into the directory
[ok]
/home/user/drush-backups/20110101170457/modules/logintoboggan.
'all' cache was cleared
[success]
You have pending database updates. Please run 'drush updatedb' or [warning]
visit update.php in your browser.

, pm-updatecode , 1.0-alpha2
1.0, . ,

Drush

535

1.0 . pm-updatecode
; ,
, ,
.
, drush pm-download modulename --dev.
25.6. --notes pm-updatecode,
Drush ,
. , pm-updatecode.
pm-releasenotes, 25.7.
2 5.7. Drupal-
$ drush @dev pm-releasenotes logintoboggan
> RELEASE NOTES FOR 'LOGINTOBOGGAN' PROJECT, VERSION 7.x-1.0-alpha2:
> Last updated: December 24, 2010 - 23:18 .
> Installed
Changes since DRUPAL-7--1-0-ALPHA1:
* arguments -> variables per change to hook_theme.

pm-releasenotes
; 25.7
logintoboggan-7.x-1.0-alpha2.

, , - -security.
25.8 ,
, ,
.
2 5 .8 . Drupal pm-updatecode
$ drush @dev pm-updatecode --security-only
Refreshing update status information ...
Done.
Update information last refreshed: Sat, 01/15/2011 - 19:57
Update status information on all installed and enabled Drupal projects:
Name Installed version Proposed version Status
Drupal core 7.0 7.0 Up to date
LoginToboggan 7.x-1.0-alpha2 7.X-1.0 Update available
No security updates available.

logintoboggan
7.x-1.0-alpha2 ,
Drush , .
(update.php). Drush
, 25.9.
25 .9. Drush- updatedb
$ drush @dev updatedb
The following updates are pending:
logintoboggan module :
7000 - Remove hardcoded numeric deltas from blocks.
Do you wish to run all pending updates? (y/n):
Finished performing updates.

536

25. Drush

, Drush
pm-updatecode, updatedb.
Drush , .
: ,
, . Drush
- -lock, 25.10.
pm-update,

25.10. Drush
$ drush @dev pm-updatecode --lock=logintoboggan
Refreshing update status information ...
Done.
Locking logintoboggan
Update information last refreshed: Sat, 01/15/2011 - 19:57
Update status information on all installed and enabled Drupal projects:
Name Installed version Proposed version Status
Drupal core 7.0 7.0 Up to date
LoginToboggan 7.x-1.0-alpha2 7.X-1.0 Locked via drush. (Update available)
No code updates available.

;
, --unlock=module_name --unlock=all.

.
?
Drush. ,
, :
$ drush @dev pm-updatecode --pipe
logintoboggan 7.x-1.0-alpha2 7.X-1.0 Update-available

--pipe Drush-. Drush



. pm-updatecode Drush
.
. ,
, ,
. ,
.

update advanced , .
Drush . Drupal 7 ,
, .

Drush
Drush
. , Drush-,
drush extras, drush make, drubuntu devel. ,
Drupal-; Devel Features.
Drupal- Drush-
,

Drush

537

. http://drupal.org/project/drush
Drupal-, Drush.
Drush Drush-,
PHP-, Drush-.
.drush.inc. Drush ,
,
. Drush :
commands Drush (/path/to/drush/commands);
, include,
(--include=/path/to/my/drush/commands) drushrc.php
({options['include'] = /path/to/my/drush/commands);

Drush, /usr/share/drush/commands;
.drush, $;
Drupal.
Drush- pm-download ,
Drush , . ,
pm-download drush_extras $HOME/.drush/drush_extras.
, Drush-.
, Drupal-, Drush-,
Devel, , Drush Drupal.
sites/all/modules. , Drupal,
.
, , Drush-
, .
25.11 , Devel @dev,
.
25.11. devel
$ drush gdev pm-download devel
Project devel (7.X-1.0) downloaded to /srv/www/dgd7/web/sites/all/modules/devel.
Project devel contains 4 modules: devel_generate, performance, devel_node_access,
devel.
$ drush @dev pm-enable devel
The following extensions will be enabled: devel
Do you really want to continue? (y/n):
devel was enabled successfully.
FirePHP has been checked out via svn to /srv/www/dgd7/web/sites/all/modules/devel/
FirePHPCore.
$ drush gdev help --filter=devel
All commands in devel: (devel)
devel-download
Downloads the FirePHP library from
http://firephp.org/.
devel-reinstall
Disable, Uninstall, and Install a list of projects.
(dre)
devel-token (token)
List available tokens
fn-hook (fnh, hook)
List implementations of a given hook and
explore
source of specified one.
fn-view (fnv)
Show the source of specified function or
method.

drush @dev help Drush


@dev. - -f ilter=devel Drush,
, Devel.
- -filter Drush ;
@dev, Drush- Devel .

538

25. Drush

, Devel, ,
FirePHP. Drush,
; , , ,
Drush-.

Drush
, , Drush, .
aliases.drushrc.php,
Drush- drushrc.php.
Drush ,
$HOME/.drush/drushrc.php. , .
. drush examples
, . ,
, example.drushrc.php. $HOME/.drush/drushrc.php:
$ mkdir $/.drush

$ examples/example.drushrc.php $HOME/.drush/drushrc.php


, . ,
:
// .
$options['uri'] = 'http://d7dg.org';
// Drupal
// ( ).
$options['root'] = '/srv/www/d7dg.org/drupal';

Drush- core-status ,
- -root
- - uri. ,
Drush,
Drupal .
Drupal URI-
, cd.
Drupal
.

Drush
,
, . , Drush
,
Drush.
; Drush
. , ,
, .
:
CLI cli;
Specific , ,
;
Site drushrc.php, Drupal (
, settings.php);

Drush

539

Drupal drush.php, Drupal (,


index.php);
Alias , ,
;
drush.php, $/.
drush.

, Drush
, . cli,
, ,
. , ,
,
. , Drupal, ,
.

,
Drush
, .
Drush. , --notes
pm-download pm-updatecode . ,
pm-updatecode ,
pm-download ,
:
$command_specific['pm-updatecode'] = ('notes' => TRUE);

, , ,
25.12. .
25 .1 2 . ,
$aliases['dev'] = array(
'root' => '/srv/www/dgd7.org',
'uri' => 'http://dev.dgd7.org',
'command-specific' => array(
'status' => array('show-passwords' => TRUE),

h
>;
- -show-passwords Drush @dev corestatus. ,
,
.


Drush ,
. . -,
, :
$aliases['all-scratch'] = array(
'site-list* => array('@dev', '@stage'),

);
Drush-
:

540

25. Drush

$ drush gall-scratch core-status "Drupal Version"


You are about to execute 'core-status Drupal Version' on all of the following targets:
@dev
@stage
Continue? (y/n):
@dev
>> Drupal version
7.0-dev
(Slstage

>>

Drupal version

7.0

-,
. ,
. , ,
, , dgd7.org
dgd7.aliases.drushrc.php
, , 25.13.
25.13.

dgd7.aliases.drushrc.php

$aliases['dev'] = array(
'root' => '/srv/www/dgd7.org',
'uri' => 'http://dev.dgd7.org',

);

$aliases['stage'] = array(
'root' => /srv/www/stage.dgd7.org,
uri' => 'http://stage.dgd7.org',

);

$aliases['live'] = array(
'remote-host' => 'host.isp.com',
'remote-user' => 'wwwadmin',
'root' => '/srv/www/dgd7.org',
uri' => 'http://dgd7.org*,

);
Drush -
. -, ,
. @dev @dgd7. dev.
( @dev,
.)
-, ;
25.13 :
$aliases[dgd7'] = array(
'site-list' => array('@dgd7.dev', '@dgd7.stage, '@dgd7.1ive'),

>;
@dgd7. liv e ,
. ,
.
Drush-, ,
Drush .
, .
.

Drush
Drupal, ,
@live .
SSH-, Drush. ,

Drush

541

,
.
Drupal.

SSH-
Drush- SSH-,
. ,
. , Drush. pushkey,
drush_extras. . ,
, . drush_extras Drupal-,
Drush-. ,
Drush.
pushkey. 25.14.
2 5 .1 4 . drush_extras pushkey
/
$ drush pm-download d ru s h _ e x tra s
P r o je c t d ru s h _ e x tra s ( 7 .X -4 .0 ) downloaded t o [su cce ss]
/h o m e /u s e r/. d ru s h /d ru s h _ e x tra s .
$ drush pushkey @ live
E n te r passphrase (empty f o r no pa ssph rase):
E n te r same passphrase a g a in :
G e n e ra tin g p u b lic / p r iv a t e rsa key p a ir .
Your id e n t i f i c a t i o n has been saved in /h o m e /u s e r/. s s h /id _ r s a .
Your p u b lic key has been saved in /h o m e /u s e r/.s s h /id _ rs a .p u b .
The key f i n g e r p r in t i s :

dl:72:ed:7c:05:c4:cb:75:75:dc:3b:c4:ba:95:0d:le user@localhost
The key's randomart image is:
+ - - [ RSA 2 0 4 8 ]------ +

o+.=
. . E+*
.00 =*

+ .+*.
+ .

wwwadmin@ host.isp.corn's password:


$ drush @ live c o re -s ta tu s
7 .0
D ru pa l v e rs io n
h t t p : / / l iv e . d g d 7 . o r g
S ite URI
Database d r iv e r
Pgsql
lo c a lh o s t
Database hostname
www-data
Database username
dgd71ivedb
Database name
Connected
Database
S u cce ssfu l
D ru pa l b o o ts tra p
Anonymous
D ru pa l user
b a r t ik
D e fa u lt theme
seven
A d m in is tra tio n theme
/ e t c / p h p 5 / c li/ p h p . in i
PHP c o n fig u r a tio n
4 .0 -d e v
Drush v e rs io n
/h o m e /u s e r/.d ru s h /d ru s h rc .p h p
Drush c o n fig u r a tio n
/h o m e /u s e r /.d r u s h /liv e .a lia s e s .d r u s h r c .p h p
Drush a lia s f i l e s

&

542

25. Drush

2 5 .1 4 ()

Drupal root
Site path
File directory path

/home/user/.drush/dev.aliases.drushrc.php
/srv/www/dgd7-live/web
sites/default
sites/default/files

core-status ,
Drush.
Drupal. .
Drush
SSH; ( ),
. .
,
, . -
Drush ,
Drush- core-rsync drush sql-sync, .
Drush. ,
; , , Drush
25.14 core-status .

Drupal

Drush- core-rsync sql-sync Drupal
. ,
, . ,
Drush core-rsync ,
- -simulate, 25.15.
2 5 .1 5 . Drupal
Drush- rsync

$ drush core-rsync @live @dev --include-conf --simulate


Calling system(rsync -e 'ssh ' -az --exclude=".bzr" --exclude=".bzrignore" --exclude=".
bzrtags" --exclude=".svn" wwwadmin@host.isp.com:/srv/www/dgd7-live/web/srv/www/dgd7/
web/);
$ drush core-rsync @live @dev --include-conf
You will destroy data from /srv/www/dgd7/web/ and replace with data from
wwwadmin@host.isp.com:/srv/www/dgd7-live/web/
Do you really want to continue? (y/n):

- -include-conf Drush settings.php.


liv e dev ,
Drush .
--in c lu d e -c o n f, ,
settings.php. , ,
settings.php .
, ;
, , settings.php.
.
; Drush , 25.16.
2 5 .1 6 . Drupal .
Drush- sql-sync
$ drush sql-sync @live @dev --c re a te -d b

WARNING: Using temporary files to store and transfer sql-dump. It is recommended that
you specify --source-dump and --target-dump options on the command line, or set '%dump'

Drush

543

or '%dumpdir' in the path-aliases section of your site alias records. This facilitates
fast file transfer via rsync. You will destroy data from dgd7devdb and replace with
data from host.isp.com/dgd71ivedb.
You might want to make a backup first, using the sql-dump command.
Do you really want to continue? (y/n):
DROP DATABASE
CREATE DATABASE

sql-sync (Access denied for


user 'www-data'g'localhost '),
, --db-su --db-su-pw.
; -
dev, ,
: , -
files. ,
. , Drupal SQL-
. , sync:
$ drush sql-sync @live @dev --structure-tables-key=common

drushrc.php.
example.drushrc.php:
$options['structure-tables'] = array(
'common' => a rra y ('c a c h e ', ' c a c h e _ filte r',
'history', 'sessions', 'watchdog'),

'cachejnenu', ' cache_page',

);
.
, cache,
drush sql-query 'show t a b l e s ; ' | grep cache.
, imagecache_action ,
.
sql-sync
, .
drush he- lea all.
, Drush SQL-
. - -sanitize, 25.17.
2 5 .1 7 .


$ drush sql-sync @dev @test --sanitize
You will destroy data from testdb and replace with data from devdb.
The following post-sync operations will be done on the destination:
*
Reset passwords and email addresses in user table
You might want to make a backup first, using the sql-dump command.
Do you really want to continue? (y/n):

Drush ;
docs/drush.api.php. , ,
(, password).
,

. ,

. , . ,

544

25. Drush


, .

Drush ; ,
Aegir, provision hostmaster. Aegir
http://community.aegirproject.org/
Drush.


sql-sync SQL- ,
.
, ,
. Drush sql-sync .
mysqldump pg_dump SQL- -. core- sync.
- SQL-. ,
, corersync, Drush
,
-. Drush ,
(
core-rsync).
, Drush
$options [' dump-dir' ]. Drush
, .
,
. ,
; ,
.
,
, .
- -source-dump - -targetdump. ,
. , ,
.
Drush
. path-aliases :
$aliases['dev*] = array(
'root' => '/srv/www/dgd7.org',
'u ri' => ' http://dev.dgd7.org',
'path-aliases' => array(
'%dump' => '/path/to/dum pfile.sql',
);
--source-dump
%dump, .
, --target-dump.
, Drush
. sql-sync - - cache, ( )
. 24 ;
sql-sync ,
.

Drush

545

{options[ 'cache' ] = 0,
.
skip-tables, .

sql-sync Drush

,
/ SSH-,
Drush .
, ,
, . Drush
. ,
, Drush .
, sql-sync Drush
. , Drush SSH
, ,
. Drush
sql-conf. , Drush ,
sql-sync - -debug:
$ drush sql-sync @live @dev --debug
[ , , ]
Running: ssh - PasswordAuthentication=
no 'wwwadmin'@'remoteserver.com' [command]
'drush --all --uri=
'V 'http://dev.dgd7.org'\'' --root='\''/srv/www/drupal'\''
sql-conf --backend' [0.05 sec, 3.7 MB]

, Drush SSH Drush- sql - -all. ,


drush help, ( 25.18).
conf

2 5 .1 8 . sql-conf
$ drush @live sql-conf --all --show-passwords
Array

[default] => Array

[default] => Array

[driver] => pgsql


[username] => www-data
[password] => secretsecret
[port] =>
[host] => localhost
[database] => dgd7db

)
)
)
- - all Drush
, . - -show-passwords
,
. sql-conf
; site-alias
, aliases.drushrc.php ( 25.19).

546

25. Drush

2 5 .1 9 .
Drupal site-alias
$ drush s it e - a lia s @ live --w ith -d b --show-passwords
$ a l i a s e s [ ' l i v e ' ] = array (
re m o te -h o s t' => 'h o s t.is p .c o m ',
' re m o te -u s e r' => 'wwwadmin',
' u r i ' => ' h t t p : / / l i v e . d g d 7 . o r g ',
'r o o t ' => '/s rv /w w w /d g d 7 ',
'd a ta b a se s' =>
a rra y (
'd e f a u lt ' =>
a rra y (
'd e f a u lt ' =>
a rra y (
'd r i v e r ' => 'p g s q l',
'usernam e' => 'w w w -d a ta ',
'passw ord ' => ' s e c r e ts e c r e t' ,
'p o r t ' => ' ' ,
'h o s t ' => 'lo c a lh o s t ',
'd a ta b a s e ' => 'd g d 7 d b ',

b
h
),
);
, ,
s q l- s y n c
. , ,
settings.php Drupal ,
.

. Drush .
aliases, drushrc. php.

sql-sync
Drush
, . ,
s q l- s y n c .
, ,
. ,
s q l- s y n c ,
, ,
. , Drush
s q l- s y n c c o re rs y n c , ,
.
, ( 25.20).
2 5 .2 0 . , ,
sql-sync
$ a lia s e s [' l i v e '] = a rra y (
're m o te -h o s t' => 'h o s t.is p .c o m ',
' re m o te -u s e r' => 'wwwadmin',
'r o o t ' => '/s rv /w w w /d g d 7 .o rg ',
' u r i ' => ' h t t p : / / d g d 7 . o r g ',
'ta rg e t-c o m m a n d -s p e c ific ' = a rra y (
's q l- s y n c ' => a r r a y ( ' s t r u c t u r e - t a b le s ' => ' u s e rs ,u s e r_ ro le s ' ) ,

Drush

547

, drush sql-sync @dev @live


- -targ et-stru ctu re-tab les= ' users, user_roles',
( drush sql-sync @live @dev).
,

@live. @live.
, Drush
sql-sync. ,
.
. -, .
Drush ( )
, , ,
. -,
. ,
drushrc.php,
settings.php Drupal. , ,
25.20, , sites @live:
$options['target-command-specific']['sql-sync'] =>
array(structure-tables' =>'users,user_roles');

;
, @live , ,
sql-sync.
; , ,
drushrc.php, , Drupal.

.
, ,
, .
.
, .

Drush
Linux bash (
), , , . 25.21
25.22 Hello World.
2 5 .2 1 . Hello World bash
h e llo w o r ld .s h :

#!/bin/bash
echo "Hello world! This machine's name is:"

uname -n4

2 5 .2 2 . helloworld.sh
$ chmod +x h e llo w o rld .s h
$ h e llo w o r ld .s h

Hello world! This machine's name is: genkan

, Drush ( 25.23 25.24).


2 5 .2 3 . Hello World Drush
h e llo w o r ld .d r u s h :

#!/usr/bin/env drush

&

548

25. Drush

2 5 .2 3 ()

drush_print(dt("Hello world! This site's name is: @name", array("@name" =>


variable_get('site_name', 'unknown'))));
helloworld.drush
$ chmod +x helloworld.drush
$ cd /srv/www/dgd7.org
$ /path/to/drush/examples/helloworld.drush
Hello world! This site's name is: The Definitive Guide To Drupal 7

2 5 .2 4 .

PHP- "<?php",
, . Drush- .drush,
bash- .sh. ,
, , PATH. ,
.
.

examples, Drush, drush/examples/helloworld.


, 25.23.
Drush .
Drupal, variable_get,
. ,
Drush Drupal .
Drush-
PHP-,
. Drush-
. , bash-,
Drush .
script;



Drush
. , drush/examples/helloworld.script
hello world; , ,
:
while ($arg = drush_shift()) {
drush_print(' ' . $arg);

// --target; "gself",
// --target
$target_value = drush_get_option('target', '@self');


, Drush-
Drush-.
; API
http://api.drush.ws.

Drush

549

drush_shell_exec drush_op_system
drush_shell_exec drush__op_system
Drush-. drush_op_system,
; ,
.
, drush_shell_exec.
. drush_shell_exec:
drush_shell_exec("tar -tf %s", $tarpath);
$output = drush_shell_exec_outputQ;
$project_dir = rtrim($output[0], DIRECTORY_SEPARATOR);

, ; drush_op_system
0, a drush_shell_exec TRUE.
drushJnvoke
drush_invoke Drush-,
. , Drupal-
devel hacked. , ,
.
#!/bin/env drush
drush_invoke(1cache-clear', 'all');
drush_invoke('pm-enable', 'devel', 'hacked');
drush_dispatch

drush_dispatch
drush_dispatch drush_invoke,
. , -
; , Drush- core-topic
, , ,
drush__dispatch.
$commands = drush_get_commands();
$command_name = function_to_select_one_command($commands);
return drush_dispatch($commands[$command_name]);

drush_mvoke_process drushJnvoke_sitealias
drush_invoke_process drush_invoke_sitealias
drush_invoke; , API
. drush_invoke_sitealias
Drupal,
, .
Drush drush_sitealias_get_record.
// core-status @dev
// "Drupal version" .*
// : drush @dev core-status "Drupal version"
$site_record = drush_sitealias_get_record('@dev');
$result_record = drush_invoke_sitealias(
$site_record, 'core-status', "Drupal version");
drush_print($result_record['output']);

drush_invoke_sitealias Drush- ,
Drupal .
, Drupal

550

25. Drush

. ;
.
drushJnvoke_process_args drush_invoke_sitealias_args
drush_
invoke_process_args drush_invoke_sitealias_args.
,
.
// sql-conf -all,
// , .
$result_record = drush_invoke_sitealias_args(
$alias_record, "sql-conf", array(), array('all' => TRUE));
$database_records = $result_record['object'];

, sql-sync
, .
, - -all, ,
sql-conf , .
(drush_invoke_process_args)
- (drush_invoke_sitealias_args), ,
,
drush_redispatch_get_options, .


, drush_invoke_process, drush_invoke_
_args ,
. ,
, ,
. :
output. . ,
, Drush- .
object. Drush-. ,
PH P-, .
. , sql-conf
.
self. ,
.
. sqlsync
( ) .
error_status. . .
log.
.
:
type , notice () warning (
);
message ;
timestamp ;
memory ;
error , (
sitealias

error).

Drush

551

,
.
error_log. .
, error.
, ,
, .
context. ,
. ,
drushrc.php .
drush_get_merged_options,
Drush.


Drush- Drush-
. ,
, Drush-
,
. Drush- ;
Drush-
,
. Drush-
, .
Drush ,
.
drush_print dt
Drush drush_print, drush_print_r dt,
print, print_r t .
Drush drush_print,
, UTF-8.
output_charset
examples/examples.drushrc.php.
dt
drush_print . , t
Drupal: . Drush t,
Drupal. A Drush
, , Drush-
Drupal. dt t .
drush_print(dt("The command !command said !exclamation", array(
'!command' => $command, '!exclamation' => {exclamation)));

drush_print, ,
Drush- , .

drush_print_pipe
Drush ,
, . , pm-list
Drush ,

552

25. Drush

. - - pipe,
.
Drush-
d ru s h _ p rin t_ p ip e , .
;
. ,
,
Drush.
drush_print_table
d r u s h _ p r i n t _ t a b le
,
,
. Pear
Consol Table (Richard Heyes) (Jan Schneider);
http://pear.php.net/package/Console_Table. Console Table
Drush; , Drush
.
, ,
.
( 25.25).
2 5 .2 5 . drush_print_table
$header = a r r a y ( d t ( ' I d ' ) , d t ( 'D a t e ') ,
d t ( 'S e v e r it y ' ) , d t ( 'T y p e ') , d t('M e s s a g e ' ) ) ;
w h ile ( $ r e s u lt = d ru s h _ d b _ fe tc h _ o b je c t($ rs c )) {
$row = c o re _ w a tc h d o g _ fo rm a t_ re s u lt($ re s u lt);
$ t a b le [] = a rra y ($ ro w -> w id , $ro w -> da te , $ ro w -> s e v e rity ,
$ ro w -> typ e , $row->message );

}
if

( $ t a il) {
$ ta b le = a rr a y _ r e v e r s e ($ ta b le );

}
a r r a y _ u n s h ift( $ ta b le , $ h e a d e r)j
d r u s h _ p r in t_ ta b le ( $ ta b le , TRUE);

Drush- w atchdog-show ,
Drupal-.
t a i l , ;
. ; TRUE
.
w a tch do g-sho w :
$ drush watchdog-show
Id Date S e v e rity Type Message
61 1 5 /Jan 09:01 n o tic e user Session opened f o r admin.
60 1 5 /Jan 08:47 n o tic e cron Cron run com pleted.

, watchdog-show
:
(
a rra y ( ' I d ' , 'D a te ',
a rra y ( '6 1 ', '1 5 /J a n
' Session.opened f o r
a rra y ( '6 0 ', '1 5 /J a n

);

'S e v e r it y ', 'T y p e ', 'M essage', ) ,


0 9 :0 1 ', 'n o t ic e ', 'u s e r ',
a d m in .', ) ,
0 8 :4 7 ', 'n o t ic e ', 'c r o n ', 'Cron run c o m p le te d .', ) ,

Drush

553

,
.
drush_print_table , , ,
. .
, ,
drush core-status,
drush_key_value_to_array_table :
$status_table['Drush version'] = DRUSH_VERSION;
$status_table['Drush configuration'] = implode(' ', $configuration_list);
drush_print_table(drush_key_value_to_array_table($status_table));

Drush- core-status (
), . ,
, .
HTML-
drush_html_to_text
Drupal- drupal_html_to_text .
, Drush-
Drupal; Drush
drush_html_to_text.

,
HTML-, , ,
. , Drush- pm-releasenotes
drush_html_to_text HTML-
, .
HTML- Drush-, Drupal,
drupal_html_to_text
HTML- .


Drush
. , ,
. :
drush_conf irm /.
drush_prompt .
, Enter
.
drush_choice ,
. drush_choice
, ,
, .
. drush_choice
drush_print_table;
,
, ,
. Drush
pm-download - - select,
.

554

25. Drush

drush_choice Drush- pm-download.


$releases ;
release release_status. Drush
,
drush_choice.
foreach($releases as $version => $release) {
$options[$version] = array(
$version, '
gmdate('Y-M-d', $release['date]), '
, $release['release_status']));

implode(

$choice = drush_choice($options, dt(


Choose one of the available releases:'));

drush_choice .
, ,* , Supported
Recommended. ,
(-). .
, , 25.5
(. Drush).
Drush ,
- -yes - - . Drush
,
- -yes,
. drush_prompt ,
, , .
, drush_
confirm drush_choice,
cancel, , drush_user_abort() ;.
Drush .


Drush
. ,
, , drush_print, drush_log
drush_set_error. .
drushjog
,
, drush_log
drush_print. Drush :
- -verbose - -debug. .
Drush- .
drush_log,
,
. drush_log
,
. , , ,
. , Drush
,
. ,

Drush

555

, Drush-
. , drush_log
drush_print:
drush_log(dt('lextension was enabled successfully.', array(
'lextension' => $extension->name)), 'ok');

:
'ok' ' success'. , .
Drush 'ok' 'success' .
, , ,
.
. ,
'o k ', pm-enable.
drush_log ' ok' ,
.
' warning'. , , ,
.
, pm-updatecode drush_log 'warning',
,
, , updatedb.
' n o tice'. , ,
.
- -verbose. Drush-,
, pm-releasenotes, -
.
' debug'. ,
, .
- -debug.
php-script, ,
.
' e rro r'. ,
.
drush_set_error. Drush drush_log 'e rr o r '
, Drush- Drush-
.
drush_log ,
.
, , .
; , ,
, , .

(, )
, .
,
, .
drush_set_error
d rush_set_error , .
, , Drush- drush_set_error,

556

25. Drush

FALSE.
Drush , , drush_set_error,
FALSE, :
return drush_set_error('DRUSH_CRON_FAILED, dt('Cron run failed.'));

drush_set_error ,
.
Drush , drush topic docserrorcodes.
.
. Drush
error: (, error:DRUSH_CRON_FAILED).
Drush- help hook.

Drush
Drush-
,
Drupal. ,
Drupal, Drush-.
,
Drush-, Drush-,
, ,
. , , .
Drush drush/examples/sandwich.drush.inc, ,
. ,
Drush- ,
, , . ,
Drush- Drush; PHP-,
, , Drush .
Drush- .
.drush.inc.
, , Drush
. Drush
Drupal. ,
Drush-, .


Drush- hook_drush_command.
sandwich,
sandwich_drush_command, , . hook_
drush_command Drupal;
, . hook_drush_command
sandwich 25.26;
make-me-asandwich.
2 5 .2 6 . hook_drush_command sandwich

/**

* of hook_drush_command().

* ,

Drush

557

* drush-

* ,
* .

* @See drush_parse_command() .

* greturn
* , ().

*/
function sandwich_drush_command() {
$items = arrayQj
$items['make-me-a-sandwich'] = array(
'description' = > "Makes a delicious sandwich.",
'arguments' => array(
'filling' => 'The type of the sandwich (turkey, cheese, etc.),

h
'options' => array(
'--spreads' => 'Comma delimited list of spreads (
e.g. mayonnaise, mustard)',

h
'examples' => array(
'drush mmas turkey --spreads=ketchup,mustard' =>
'Make a terrible-tasting sandwich that is lacking in pickles.',

),
'aliases' => array('mmas'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap at all.

);

return $items;

}
description, arguments, options examples
.
, , .
, , Drush
,
. . ,
, , .
. ,
25.26 drush make-me-a-sandwich,
drush mmas. ,
.
bootstrap Drush-
Drupal. DRUSH_BOOTSTRAP_DRUSH , Drush .
. Drush- Drupal-,
Drupal , ,
. , DRUSH_BOOTSTRAP_DRUPAL_LOGlN , Drush
Drupal
, . DRUSH_BOOTSTRAP_DRUPAL_LOGIN
,
. ; ,
Drupal, . ,
- , .
DRUSH_BOOTSTRAP_MAX,
,

558

25. Drush

Drush-. Drush-
Drupal
. , pm-releases
.
, .
, ;
. , drush docs-commands
.


Drush
. drush,
.
(_);
. Drush-
, ,
. ,
Drush- sql-sync sql (
sql.drush.inc).
drush, sql sql-sync, drush_sql_sql_sync
drush_sql_sync. , Drush
. , sql-sync,
:
Functoin drush_sql_sync($source = NULL, $destination = NULL) {
$source_settings = drush_sitealias_get_record($source)j
$destination_settings = drush_sitealias_get_record($destination);
// sql-sync ...

}
, Drush- PH P-.
Drush- Drush-;
. Drush
, .
.


Drush-
Drush- Drush-
, .
,
drush_print_pipe.
PHP-,
Drush-, . Drush
. ,
'object' , drush_backend_invoke.
Drush : , Drush-
sql-conf ;
, sql-sync
Drupal.

Drush

559


Callback
;
, .
, ,
, .
, Drush-
drush_print_f ile, .
docs-readme 25.27.
2 5 .2 7 . Drush-

Callback
$items[docs-readme'] = array(
'description' => dt('README.txt'),
'hidden' => TRUE,
'topic' => TRUE,
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'callback' => 'drush_print_file',
'callback arguments' => array(DRUSH_BASE_PATH . '/README.txt'),

>; 'hidden' 'topic' Drush-.


, Drush,
( drush_dispatch). 'topic'
drush topic.
'callback' Drush drush_
print_f ile , drush_docs_readme.
,
. drush_print_f ile ,
docs-readme ,
README.txt:
drush_print_file (DRUSH_BASE_PATH . '/README.txt')


Drush- .
drush_invoke ,
.inc.
, .inc. ,
sql-sync sync.sql.inc.

Drush
Drush , .
, .
. Drush
25.28.
2 5 .2 8 . Drush

function sandwich_drush_help($section) {
switch ($section) {
case 'drush:make-me-a-sandwich':
return dt("This command will make you

&

560

25. Drush

2 5 .2 8 ()

a delicious sandwich, just how you like it.");


case meta:sandwich:title':
return dt("Sandwich commands");
case 'meta:sandwich:summary':
return dt("Automates your sandwich-making business workflows.");

}
}
,
Drush.
: meta:COMMANDFILE:title meta :COMMANDFILE: summary.
.
Drush- help --filter,
, 25.29.
2 5 .2 9 . Sandwich

$ drush help --filter --include=examples


Select a help category:
[0] :
Cancel
[1] :
Core drush commands
[2] :
Field commands: Manipulate Drupal 7+ fields.
[3] :
Project manager commands: Download, enable, examine, andupdate
your
modules and themes.
[4]
SQL commands: Examine and modify your Drupal database.
[5] :
Sandwich commands: Automates your sandwich-makingbusiness workflows.
[6]
User commands: Add, modify, and delete users.

5
Sandwich commands: (sandwich)
make-me-a-sandwich Makes a delicious sandwich.
(mmas)
$ drush help make-me-a-sandwich --include=examples
This command will make you a delicious sandwich, just how you like it.
Examples:
drush mmas turkey
Make a terrible-tasting sandwich that is lacking in pickles.
--spreads=ketchup,mustard
Arguments:
filling

The type of the sandwich (turkey, cheese, etc.)

Options:
--spreads

Comma-delimited list of spreads (e.g. mayonnaise, mustard)

Aliases: mmas

Drush . drush_set_error
,
. error:,
drush:, .

Drush-
Drush-
, , . -
, Drush ,
.
. 25.2.

Drush

561

2 5 .2 .

Init

drush_HOOK_init

init .

drush_
bootstrapjnax.
,

Validate

drush_COMMANDFILE_HOOK_validate

,
.
,

Pre-command

drush_COMMANDFILE_pre_HOOK

Command

drush_COMMANDFILE_HOOK

Post-command drush_COMMANDFILE_post_HOOK

Rollback

-
Drush-
drush_set_error,
.

_rollback
, .
, drush_pm_updatecode ,
drush_pm_updatecode_rollback

[*]_rollback

HOOK ,
a COMMANDFILE , . ,
, ,
:
. , devel
Drush-, devel.drush.inc. devel
Drush- pm-enable :
fu n c tio n drush_devel_post_pm_enable() {
$modules = fu n c _g et_a rg s();
i f ( in _ a r r a y ( 'd e v e l', $modules)) {
drush_devel_download();

}
}
, Drush- pm -enable
d ru s h _ s e t_ e rro r. devel ,
;
drush_devel_dow nload , .
, .
,
pre_pm_enable.
, Drush- ,
. ,
. ,
, --d eb u g - -sh o w -in vo ke.
Drush ,

562

25. Drush

. , , [*].

, grep. ,
mycommand Drush- s ta tu s ,
:
$ touch $HOME/.drush/mycommand.drush.inc
$ drush status --debug --show-invoke 2>&1 | grep --c o lo r= a u to mycommand
drush_mycommand_core_status_validate
drush_mycommand_pre_core_status
drush_mycommand_core_status
drush_mycommand_post_core_status

2>&1. 2>
, &1 ,
. Drush ,
--s h o w -in v o k e , ;
, .
grep. --c o lo r = a u to grep
Linux.
, , s ta tu s
v a lid a te , pre, post main.
,
Drush, Drush-.
drush_com mand_invoke_all drush_com m and_invoke_all_ref;
, ,
, .
, . , Drush-
d ru s h _ p rin t_ h e lp , Drush-,
d ru s h _ h e lp _ a lte r hook :
drush_command_invoke_all_ref( ' d ru s h _ h e lp _ a lte r' , $command);

Drush- {command,
, . ,
Drush- post,
, . , Drush
. to p ic _ d ru s h _ h e lp _ a lte r ,
, ,
,
. to p ic _ d r u s h _ h e lp _ a lte r 25.30.
2 5 .3 0 . topic_drush_help_alter
fu n ctio n topic_drush_help_alter($command) {

{implemented = drush_get_commands();
foreach ($command['topics'] as $topic_name) {

11

. $command .

$command['sections']['topic_section'] = dt('Topics');
$com m and['topic_section' ] [$topic_name] =
dt($im plem ented[$topic_nam e][ ' d e s c rip tio n ' ] ) ;

>
}
Drush-
Drush.
API Drush,
drush to p ic d o c s-ap i.

563

, Drush
Drupal, ,
, ,
Drupal. Drush-
Drush-,
, ,
.
, Drush ,
; , ,
, Drush- .
,
Drush:
README.txt drush ;
d ru s h h e lp Drush-;
d ru s h topic , Drush;
Drush , Drush,
, API
(. http://drush.ws);
Drush
Drush (. http://drupal.org/project/issues/drush).
,
. Drush
, , .
; !

26. Drupal

, , .
: , ,
. , .
.
. , .
, ,
. ,
. , , ?
, , , . ,
;
, .

. ,
. :
, .
,
, . ,
,
. ,
, . :
- .
, ;
,
. .
,
.
, , .
.
Drupal 7. ,
. , Drupal
, ,
.

?

. , ,
- . ,
, . ,
.
. .
-,
;
. ,
? ?

565

, :
, , ,
, , .
. ,
; , .
,
. ,
.
.
. ,
, ,
. .
:
,
. , Drupal
, Drupal 7 .

.
, HTML-.
,
, , ,
.
. , -
.
. ;
, , ,
,
. :
. , ,*
.

.
. ,
- .,

Drupal HTML- ,
. admin/
config/development/performance
. , ,
, .
, .
: .

( )
Boost (drupal.org/project/boost).
, .

566

26. Drupal

,
. , very_slow_find().
:
$cache = cache_get(1very_slow');
if ($cache) {
$very_slow_result = $cache->data;

else {
// .
$very_slow_result = very_slow_find();
cache_set('very_slow', $very_slow_result);

}
. ,
; , .
, ,
. very_slow
(cid), , a $very_slow_result .
. ,
, :
,
, ,
( ). cache_get, cache_set
,
Drupal, .
:
, .
Drupal ,
, Drupal , . , .
( ),
;
, .



. , :
, . Drupal
,
. . ,
( AJAX) , ,
. Drupal
, settings,
php, /sites ; (
Drupal) /sites/default/settings.php:
$conf['cache_backends'][] = 'includes/cache-install.inc';
$conf[,cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['cache_default_class'] = 'DrupalFakeCache';

, ,
(
admin/config/development/performance).

memcached

567

, ,
Drupal.
$ c o n f s e ttin g s .p h p
Drupal. ,
, ,
, .
, ,
. , :
UI, .
, ,
.
; ( $conf [ ' cache_backends ' ]),
, ( $conf [ ' c a c h e _ d e fa u lt_ c la s s ' ]).
, Drupal
.

memcached
.

memcached
. ;
Drupal (, MySQL).
memcached
, .
Drupal,
Drupal, ,
.
memcached ,
:

Drupal, . memcached
, .
Drupal. , , MySQL,
- .
memcached : , -
Drupal-. memcached.org.
. , - ,
memcached. ,
, memcache memcached.
, .
memcached. - :
peel i n s t a l l memcached

.
, Debian Ubuntu :
a p t-g e t i n s t a l l php5-memcached

, , Drupal memcached,
Memcache (drupal.org/project/memcache).
, .

568

26. Drupal

Varnish

Varnish. .
.
Drupal, , Drupal .
Boost,
Drupal.
Varnish, .
, .
Varnish . www.varnish-cache.
/, Drupal drupal.org/project/varnish.


, , .
.
, (
memcached) (
Varnish).
, . ;
memcached ,
. , ,
.
:
( / ,
), .
(Create),
(Read), (Update) (Delete), CRUD.
- SQL- .
, SQL-
( MySQL/MariaDB/Drizzle, PostgreSQL, Oracle SQL Server Microsoft)
.
SQL , SQL-
? , ,
? , SQL,
?
, , SQL.
. ,
, MySQL PostgreSQL, , , , UNIREG
( MySQL) Postgres INGRES ( PostgreSQL).
,
, ,
. , ,
, .
.
, ,
, . ,
. , ,
. , .

569

,
. ,
,
.
, ,
. ,
; , .
: , Varnish
, .

ST-506 Shugart Technologies,
1980 , 5 . DVD-.
$1500. $300 000 1980 ;
.
300 $300 ( ).
.
3000 (3 ).
0,04 .
2 $80.
, . 1981
ST-506 170 , ST-412 85 .
8-10 , 3 .
100 . ( ,
). , ST-506 ,
100 200 .
-,
2 .
. , ,
, 100 .
1980 64 ,
$400, 1 $6200 ( 1980 ).
64 ( ) $2000;
3 . .
1980 1 -2
(Intel iAPX 432, Motorola 68000). (IBM
POWER7) .
$200-350 .

, ,
,
SQL-. . ,
.
.
, . ,
, ?
, ?
,
, .
. Drupal 7
, , Drupal ,
.

570

26. Drupal

, ,
. ,
, , ,
, , . ,
. ( ;
, ,
, - .)
, .
:
, .
, .
, , SQL
. ?
.

? , .
, ,
? ,
, ,
.
, ,
, :
avocado
40, 60, 233
chorizo
50, 60, 155

- ,
, ,
, . ,
, , :
avocado
Guacamole
40
Tortilla Soup
233
Warm Chorizo Salad Cesar style
60
chorizo
Black Bean Chorizo Burritos
50
Scrambled Eggs Mexican style
155
Warm Chorizo Salad Cesar style
60

,
, .
. ,
(Scrambled Eggs Mexican style), ,
,
, , .

571

, ,
.
? ,
, .

. , 1000 ,
. 2000
.
:
avocado
bacon
30, 37, 48

chorizo
60

bacon
avocado
30, 37, 48

chorizo
70

. .
. .
, ;
8 7 = 56 ,
56 !
avocado-bacon bacon-avocado,
, .
. SQL
. SQL-:
,
, - SQL-
. Drupal!
Drupal .
(Node), ,
(Comment).
page, .
, , ,
. ,
page. , , 200 000
story, 50 000 , 200 000
, , ,
50 000 .
.
,
. -
,
.
. . ,
: ,
()?
, SQL.

572

26. Drupal

NULL SQL
NULL ;
. NULL
. , - .
, NULL.
IS NULL. , :
mysql> SELECT 0 > NULL, 0 = NULL, 0 < NULL, 0 IS NULL, NULL IS NULL;
| 0 > NULL | 0 = NULL | 0< NULL | 0 IS NULL| NULL IS NULL
|

NULL |

NULL |

NULL |

0 |

|
1 |

.
NULL.
. Drupal ( , )
, , , .
, ,
NULL.
NULL
, :
CREATE TABLE testl (a int, b int);
CREATE TABLE test2 (a int, b int);
INSERT INTO testl (a, b) VALUES (1, 0);
INSERT INTO test2 (a, b) VALUES (NULL, 1);
SELECT testl.a testl_a, testl.b testl_b, test2.a test2_a, test2.b test2_b
FROM testl
LEFT DOIN test2 ON testl.a=test2.a
WHERE test2.a IS NULL;
| testl_a | testl_b | test2_a | test2_b

1 |

0 |NULL |

NULL

, test2 (NULL, NULL). LEFT JOIN


, .
SELECT ,
.
1 = NULL , test2
. , , , ,
1 = NULL , NULL.
. ,
test2_a, NULL, JOIN , testl.a=test2..
JOIN .
, NULL,
JOIN. ,
. ,
LEFT JOIN.
,
. SQL-
( ,
). ,

573

.
.


.
, , ,
( ).
, , ,
, ( SWIFT
). , , ,
- ,
. , .
, ,
ACID (Atomic, Consistency, Isolation, Durability ,
, , ):
. .
.
: ,
, .
. , ,
.
.
.
- ,
BASE (Basically Available, Scalable, Eventually consistent
, , ):
. ,
. , ,
, . ,
. ,
.
.
.
- ,
. , ,
, . ,
, .
. ,
, . , .
, .
-, ,
. ,
. - .
, (
ACID) (
BASE), :
( ).

574

26. Drupal

,
ACID BASE, , , . , BASE
, .
, ,
, .
, .
,
. ,
, ,
, ,
. : BASE
( , ),
ACID ( , ). ,
CAP (Consistency, Availability, Partition tolerance ,
, ) .
,
.
, :
, ,
. ,
. , , ,
.
,
.
, , ,
. ,
, .
, BigTable,
60 Google, .
, : ,
. , ,

( ),
, - . ,
,
, , ,
, .
:
(), ,
, (
). -.
(
), . , ,
, , ,
. .
, ,
Send.
, - () ,
().

MongoDB

575

, SQL- ACID, -
, BASE. ,
,
.
CouchDB, 2005 . 2008- Cassandra,
2009- MongoDB.
2009
NoSQL. , , SQL
, ACID ( , MySQL
SQL , ACID),
SQL, .
, JOIN .
MongoDB, Drupal.

MongoDB
MongoDB : try.mongodb.org.
,
. mongodb.org/downloads;
. , Drupal,
drupal.org/project/mongodb.
MongoDB Drupal 7,
MongoDB. ,

Drupal.
MongoDB JSON (
). SQL-.
,
SQL-. ,
MySQL .
MySQL ,
MongoDB . :
{ title: 'first document', length: 255 },
{ name: 'John Doe', weight: 20 }

. . CREATE TABLE ,
.
SQL? !
db.people.insert({ name: ['Juan', 'Carlos', 'Alfonso', 'Victor', 'Marla', 'de',
'Borbon', 'y', 'Borbon-Dos', 'Sicilias'], title: 'King of Spain'})

Carlos

, .
:
db. people, find ({name: 'Carlos'}).

db.test.insert({
'title': 'This is an example',
'body': 'This can be a very long string. The whole document is limited to a number of
megabytes.', .
'votes': 56,.
'options':

&

576

26. Drupal

'sticky': true,
'promoted': false,

>
comments': [
'title': 'first comment',
'author': 'joe',
'published': true,

'title': 'first comment',


'author': 'harry',
'homepage': 'http://example.com',
'published': false,

}
]
;
To (, . . ),
, ( title ) , (votes),
(options. sticky), (comments) (
, options).
. (
4 ; 16 , 32 );
- .
, ?
. , (
) .
, SQL-:
,
.
:
db.test.find({title: /AThis/});
db.test.find({'options.sticky': true});
db.test.find({comments.author': 'joe'});

, find , insert.
find 1 ,
This.
. , .
.
Drupal 7, , ,
. MongoDB. :
SQL (,
) , (,
, , , ),
. , ,
, ,
. ,
, . MongoDB
,
, favorite created.
, SQL- . MongoDB
,

MongoDB

577

SQL-, .
Drupal 6 , Drupal 7
API .
MongoDB ,
settings.php ( sites/default sites) :
$conf[ 'field_storage_default'] = ' mongodb_field_storage';
storage .
, ,
.
MongoDB
, , , . . ,
, .
, .
:
= db.test.findOne({nid: 12345678});
o.votes++;
db.test.save(o);

,
. , ,
. .
:

= db.test.findOne({nid: 12345678});

votes 56.

o.votes++;


= db.test.findOne({nid: 12345678});

votes 56.

db.test.save(o);

votes 57.

o.votes++;


db.test.save(o);

votes 57.
MongoDB :
db.test.update({nid: 12345678}, {$inc : { votes : 1 }});

, votes
1 57.
, votes
1 58.
. ,
. , update JSON-;
, $inc,
.

578

26. Drupal

:
db.test.update({nid: {'$in': [123, 456]}, {
$inc : { votes : 1 }}, {multiple:1});


( ), .
,
, , .
, MongoDB :
, ,
. MongoDB ,
: ,
.
MongoDB
. ,
. views.
,
views 1. ,
, Drupal, -
, GIF- 1x1.
<?php
if (!empty($_GET['nid']) && $_GET[,nid'] == (int) $_GET['nid']) {
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
require_once DRUPAL_ROOT . '/sites/all/modules/mongodb/mongodb.module';
$find = array('_id' => (int) $_GET['nid']);
$update = array('$inc' => array('views.value' => 1));
mongodb_collection('fields_current', 'node')->update($find, $update);

>
header('Content-type: image/gif');
header('Content-length: 43');
header(Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
headerf'Expires: Sun, 19 Nov 1978 05:00:00 GMT");
header("Cache-Control: must-revalidate");
printf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%
c%c%c%c', 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 33, 249, 4,
1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59);

, , stats.php Drupal
node.tpl.php :
<img src="<?php print base_path() . 'stats.php?nid=' . $node->nid; ?>"/>


Varnish.
? -.
PH P- , - , ,
. . MongoDB
. , MongoDB
,
. , - ,
.

MongoDB

579

2011
. MongoDB
, .

, .
mongod -dur .

,
Drupal , :
. ; ,
. MongoDB
. mongod Drupal-
settings.php ( sites/default sites) :
$conf['session_inc'] = DRUPAL_ROOT
.

,/sites/all/modules/mongodb/mongodb_session/mongodb_session.inc,;

MongoDB , .
, -
( ,
URL-), SQL-
, (TRUNCATE).
, ,
. ,
, - .
MongoDB , N
, , .
,
. ,
Drupal ,
. ,
-.
, mongodb_watchdog,
dblog.
, Drupal 7 ,
MongoDB. ,
MongoDB , ,
SQL.
settings.php :
$conf['queue_default_class1] = 'MongoDBQueue';

, , MongoDB ,
,
. ,
memcache .

Null MongoDB
, , MongoDB SQL.
,
NULL ( MongoDB
).

580

26. Drupal

MongoDB , SQL,
. find
, NULL :
db.test.find({something:null}) ;

, NULL. .
,
, MongoDB ,
. NULL
, .
, , .
. , MongoDB ;
TRUE FALSE, NULL.
, :
NULL:
>
>
>
>
>
{
{

db.test.dropO
db.test.insert({a:l});
db.test.insert({something:null});
db.test.insert({something:l});
db.test.find({something:null});
"a" : 1 }
"something" : null }#

, :
> db.test.find({something:{$in: [null], $exists:true}});
{ "something" : null }

$in $exists.

NULL

1:

> db.test.find({something: {$gte: null }});


{ "" : 1 }
{ "something" : null }

something,
. : NULL
($gte), . ,
something 1, ,
NULL .

, ,
.
, . ,
Drupal 7.
, Drupal
. , ,
, , . ,
Drupal.

,
dgd7.org/scale.

27. Drupal

Drupal
, ,
() Drupal.
, Drupal
.
,
Drupal. , Drupal-
.
, . Drupal
, (
) .1
- - U R L , -
.
, .

Drupal
, ,
Drupal,
. Drupal-
( ) ,
, , Drupal
.
27.1 , (outrageous message)
X H T M L -. outrageous
.
2 7 .1 .
<?php
fu n c tio n outrageous_m enu() {
$ ite m s ['o u tr a g e o u s '] = a r r a y (
' t i t l e ' => 'O utrageous message',
'access c a llb a c k ' => TRUE,
'page c a llb a c k ' => 'outrageous_m essage',

>J
r e tu r n $ ite m s ;

}
fu n c tio n outrageous_m essage() {
/ / .
/ / t ( ) - .

&

' , Drupal 6,
(1 Nftgyesi) (Peter Wolanin). ,
.

582

27. Drupal

$message = t ( ' A

teddy bear is a cud dle w ith fo u r paws on th e e n d . ') ;

/ / .
$tim e = d a te ('M d, Y ') ;
$page = a rra y (
'#m arkup' => "$ tim e : $message",

);
re tu rn $page;

, o u tra g e o u s_ m e n u ( ), , ,
, .
P H P -. , o u tra g e o u s_ m e ssa g e ( ), ,
. 27.1.
'title1=> 'Outrageous message',

$items['outrageous']

-Nr

O u tr a g e o u s m e s s a g e \

d70.locaihost 8 0 8 2 /o u trag eo u s

D a s h b o e 'd

A d d c o n te n t

C o n ten t

S tru c tu r e

A p p e a ra n c e

P e o p le

M o d u le s

C o n ftg u ra H o n

R e p o r ts

H eip

< c o n te n t

Path into Drupal

Outrageous message
Jan 19,2011: A teddy hear is a cuddle with four paws on the end.
Navigation

A{idtfcmtem
Outrageous message

. 2 7 .1 . 27.1
Drupal-.

,
o u tra g e o u s _ m e n u () Drupal
, h o o k jn e n u Q .1 ,
outrageous, hook_menu,
o u tra g e o u s _ m e n u (). hook_m enu() , Drupal
, Drupal
. ,
, Drupal.
outrageous.m odule.

1 Drupal api.drupal.org/api/group/hooks.
hook menu api.drupal.org/api/function/hook_menu/6.

Drupal

583

DRUPAL
27.1 . Drupal,
, Drupal-.
, Drupal
.
.
27.1 outrageous.module, Drupal ,
outrageous. , Drupal
outrageous
outrageous_hookname().
, Drupal ,
outrageous_menu().

. PHP- function_exists($function_name) Drupal
, .

Drupal index.php,
Drupal. ,
Drupal, -
U R L - , index.php.
http://exam ple.com h ttp : / /e x a m p le . c o m / in d e x .p h p .
U R L - , Drupal. ,
http://exam ple.com /outrageous Drupal h t t p : / /
exam ple, com /in de x.p hp ?q= ou trage ou s. q Drupal ,
o u tra g e o u s .
27.1, U R L - http://exam ple.com /outrageous
o u tra g e o u s , , ,
o u tra g e o u s _ m e n u (), $ ite m s [ o u tra g e o u s '].
,
.
$ ite m s 'pag e c a llb a c k ', , o u tra g e o u s_ m e ssa g e ().
$items .
, ,
.
'access
c a llb a c k . (TRUE
), .
. 27.1 ,
. Drupal , ,
,
.
, .
U R L - Drupal
(. 27.2):
1. h ttp ://e x a m p le .c o m /o u tra g e o u s h t t p : / / e x a m p l e . c o m / i n d e x .
p h p? q= ou tra geo us.

2. q, o u tra g e o u s , Drupal.
3. ,
$ ite m s [ 'o u t r a g e o u s ']
, .

584

27. Drupal

4. 'access
c a l lb a c k '. TRUE .
5. 'title'.
Outrageous message.
6. , o u tra g e o u s _
message. , .
7. Drupal ,
. ,
, . 27.1.

http://example.com/outrageous

path =
"outrageous"

\
/



SELECT path, access_callback, page_callback, title FROM menu_router
WHERE path IN ('outrageous');
path

access_callback

page_callback

title

outrageous

outrageous_message

Outrageous message

.
1 ^>

DLI9AD9?^

. 27.2.

URL-

585

-, Drupal,
,
Drupal . -
, . ,
Drupal.

Drupal menu_router. 27.1
, .
menu_router
.


27.1 outrageous. ,
.
o u tra g e o u s /d o g /f r ie n d (. 27.3).
, o u tra g e o u s
. 27.2 ,
. ,
(. . 27.1).
fjf
& Outrageous m essage {I Path

4*

f d70.locaihost:8082/ouCfageous/dog/friend

........................... :.......... ...... . ........*....----A

Dashboard

Add content

Content

Structure

Appearance

People

Modules

Configuration

Reports

Help

Find content

Path into Drupal

Outrageous message
Jan 19, 2011: A dog is afriend with four paws on the endNavigation
Add content
Outrageous message

. 2 7 .3 . Drupal
2 7 .2 . Drupal
h t t p : / /lo c a lh o s t/ o u tr a g e o u s / d o g / f r ie n d

/**
* ,
* .

&

586

27. Drupal

27 .2 ()
*/
fu n c tio n outrageous_m essage($anim al = 'te d d y b e a r ', $noun = 'c u d d le ') {
/ / .
$message = 'A %animal is a %noun w ith fo u r paws on th e e n d . ';
/ / %animal %noun $anim al $noun.
/ / t ( ) ,
/ / .
/ / t ( ) , $anim al $noun - ,
/ / XSS- .
$message = t($m essage, a rra y ('% a n im a l' => $ a n im a l, '%noun' => $ n o u n ));
/ / .
$tim e = d a te ('M d, Y ') ;
$page = a rra y (
'#m arkup' => "$ tim e : $message",

);
r e tu r n $page;



, . Drupal
( ),
. Drupal .
, , ,
. .
. 27.1 42.
2 7 .1 .

node/42

#42

node/42/edit

#42

node/42/revisions

#42

:
+ + .

, ( v ie w
n o d e /4 2 ).
, 27.3.
2 7 .3 .
/**
* $ a rg l .
* $arg2 .

*/
f u n c tio n n o d e _ c a llb a c k ($ a rg l, $arg2) {
/ / $ a rg l - , ,
i f ( is _ n u m e r ic ($ a r g l)) {
$node = n o d e _ lo a d ($ a rg l);

>
//
if

, ,
($node) {

if
if

($a rg2 == ' e d i t ' ) . . .


($a rg2 == r e v is io n s ')

587

...

}
}

:
. , ,
n o d e /4 2 /s e n d ? n o d e / in t e g e r / a c t io n
, ,
.
i f {...} .
no de/add,
Drupal.
.
,
.
.
,
.
27.4.
2 7 .4 .
/**
*

hook_menu().

*/
fu n c tio n node_menu() {
$ ite m s ['n o d e /a d d '] = a rra y (
' t i t l e 1 => 'Add c o n t e n t ',
'page c a llb a c k ' => ' node_add_page' ,
'access c a llb a c k ' => '_node_add_access' ,

>;
$ ite m s [' node/% node'] = a rra y (
' t i t l e c a llb a c k ' => ' n o d e _ p a g e _ title ',
' t i t l e argum ents' => a r r a y ( l) ,
'page c a llb a c k ' => 'nod e_ pa ge_ vie w ',
'page argum ents' => a r r a y ( l ) ,
'access c a llb a c k ' => ' node_access' ,
'access argum ents => a r r a y ( ' v ie w ', 1 ),

)J
$ ite m s [' n o d e /% n o d e /e d it' ] = a r r a y (
' t i t l e ' => ' E d i t ' ,
'page c a llb a c k ' => 'n o d e _ p a g e _ e d it' ,
'page argum ents' => a r r a y ( l ) ,

)J
re tu r n $ ite m s ;


. node.module.
node_menu(
.
1 node_menu() Drupal: api.drupal.org/api/drupal/modules--node--node.module/function/node
menu/7.

588

27. Drupal


.
node/add no de_add_page( )
, (. 27.4).

. _node_add_access () 'access
c a llb a c k . 27.1 ' access c a llb a c k ' => TRUE,
. 27.4
, .
Add content t Path into Drupal

~ ~ ...P ]

http://d7,localhost:8082/node/add

D ash b o ard

A dd c o n te n t

F in d

C o n te n t

S tru c tu re

A p p e a ra n c e

P e o p le

M o d u le s

C o n fig u ra tio n

R e p o rts

H eip

content

H eiio a d m in

to y out

Edit shortcuts

Horn**

Add content

Article
use snides for time- sensitive content itke news, press releases or 09 posts.

Baste page
Use basic pages for your sialic content,, such as an About us' page,

. 2 7 .4 . node/add ,
. node_add_page()

DRUPAL 7
Drupal 7 , .
(delivery callback),
;
drupal deliver html page. ,
.
, , .

( 23).
,
. Drupal 7
API.1

'node/%node %node,
, .
1 api.drupal.org/api/drupal/m odules-system --system .api.php/function/hook_m enu/7

589

node/42, n o d e /fo o . . node/add,


- ,
node/add,
.


Drupal ,
, %node, ,
,
. , ;
(, %foo),
f o o _ lo a d ( ). %node n o d e _ lo a d ( ).
node/42 n o d e _ lo a d (4 2 )
. $node
, 42. , ,
. 27.4
, ,
. 27.5
'node/% node'.
2 7 .5 . node/% node
$ ite m s ['n o d e /% n o d e '] = (
'page c a llb a c k ' => ' node_page_view ',
'page argum ents' => a r r a y ( l ) ,

);


no de _ p a g e _ vie w ( ), .
' page a rg u m e n ts' , ,
. a r r a y ( 1 ) ,
1. , a r r a y ( l )
%node. ,
$node, .
node/4 2 :
/ / _ loa d 42.
$node = n o d e _ lo a d (4 2 );
/ / $node.
re tu r n node_page_view($node ) ;


27.6.

' node/% node' .

2 7 .6 . node/% node
$ ite m s ['n o d e /% n o d e '] = a rra y (
' t i t l e c a llb a c k ' => 'n o d e _ p a g e _ title ',
' t i t l e argum ents' => a r r a y ( l) ,
'page c a llb a c k ' => ' node_page_view ' ,
'page argum ents' => a r r a y ( l ) ,
'access c a llb a c k ' => 'node_access' ,
'access argum ents' => a r r a y ( ' v ie w ', 1 ),

);

590

27. Drupal

27.1 ' t i t l e ' ,


. 'node/% node '
' t i t l e c a llb a c k ' ' t i t l e a rg u m e n ts '.
.
n o d e _ p a g e _ _ title (), , ' t i t l e a rg u m e n ts ' => a r r a y ( l ) ,
$node, n o d e _ p a g e _ v ie w ( ).
$node.

,
$node. 'a c c e s s c a llb a c k ' access a rg u m e n ts ', ,
, ,
node/4711:
/ / 1 %node.
$node = no de_load(4711);
/ / $node ,
r e tu rn n o d e _ a c c e s s ('v ie w ', $node);

'node/% node ' ,


,
.
, ,
.
, ,
, .


, ho ok_ m enu _a lter.
, Drupal,
. ,
, ,
.


, ,
? , ?
? n o d e /1 2 3 4 5 /e d it,
27.4:
$ ite m s [ ' node/%node' ]
$ ite m s [ ' n o d e /% n o d e /e d it' ]

node/%node n o d e /% n o d e /e d it,
.
Drupal .
:
n o d e /1 2 3 4 5 /e d it:
n o d e /1 2 3 4 5 /e d it
node/12345/%
n o d e /% /e d it
node/%/%
node/12345
node/%
Node

591

%. ,
, , ,
Drupal , . S Q L
:
SELECT * FROM menu_router
WHERE path IN
( ' n o d e /1 2 3 4 5 /e d it ',
'n o d e /1 2 3 4 5 /% ',
'n o d e /% /e d it' ,
n o d e /1 2 3 4 5 ',
'node /% ',
'n o d e ')

,
, node/1 2 3 4 5 /
e d it ? .
. (,
node e d i t ) , .
,
.
n o d e /1 2 3 4 5 /e d it . 27.2.
2 7 .2 . Drupal ( drupal.org/node/109134)

node/12345/edit

111

n o d e /12345/%

110

node/% /edft

101

node/% /%

100

node/12345

11

node/%

10

Node


. ,
S Q L -.
. S Q L , n o d e /1 2 3 4 5 /e d it, :
SELECT * FROM menu_router
WHERE path IN
( , n o d e /1 2 3 4 5 /e d it',
' node/12345 /%',
'n o d e /% /e d it
' node/12345' ,
'n o d e /% ',
'n o d e ')
ORDER BY f i t DESC
LIMIT 0, 1


. menu__router ,
404 (Not Found). Drupal-, ,
, ,
, .

592

27. Drupal

Drupal
, Drupal.
, ,
Drupal-
. ,
h o o k_ m e n u _ a lte r .


Drupal. ,
?
Drupal, ?
Drupal ,
. h o o k_ m e n u _ a lte r.
h o o k_ m e n u _ a lte r
.
. -
,
outrageous ,
, ( 27.7).
2 7 .7 . outrageous
<?php
fu n c tio n outrageous_m enu() {
$ ite m s ['o u tr a g e o u s '] = a rra y (
' t i t l e ' => 'O utrageous message',
'access c a llb a c k ' => TRUE,
'page c a llb a c k ' => 'o u tra g e o u s jn e s s a g e ' ,

);
re tu r n $ ite m s;

}
fu n c tio n outrageous_m essage() {
/ / .
/ / t ( ) - .
$message = t ( ' A ted dy bear i s a cud dle w ith fo u r paws on th e e n d . ') ;
/ / .
$tim e = d a te ('M d, Y ') ;
$page = a rr a y (
'#m arkup' => "$ tim e : $message",

);
r e tu r n $page;

m o re o u tra g e o u s _ m e n u _ a lte r() h o o k_ m e n u _ a lte r,


+ ,
$ ite rn s.
2 7 .8 . moreoutrageous
<?php
fu n c tio n m oreoutrageous_m enu_alter(& $item s) {
/ / o u tra g e o u s '.
$ ite m s ['o u tr a g e o u s '] [ 'page c a llb a c k '] = 'm oreoutrageous_message ;

593

fu n ctio n
//

m oreoutrageous_m essage()

$m essage
'I
//

= t(

am a m a c h i n e f o r

tu rn in g

orange

ju ice

in to

Drupal p a t c h e s . ') ;

$tim e

= d a te ('M

$page

= array(

#m arkup'

=>

d,

Y ') ;

"$tim e :

$m essage",

);
re tu rn

$page;

$ ite m s ,
hook_menu .
, .
'page c a llb a c k ',
o u tra g e o u s _ m e n u () outrageous, ,
m ore o u tra g e o u s_ m e ssa g e () moreoutrageous (. 27.5).
0

ft

&

Outrageous m essage f Path into Orupai

{ 4 ) > ' \ 0 - j

X ) \J k j ( i :

http: / / d7.iocathosi:8082/ outrageous

* Powered i f A )

Outrageous message I Path SotoD


D ash b o a rd

A dd c o n te n t

C o n te n t

S tru c tu r e

A p p e a ra n c e

P e o p ie

M o d u e s

C o n fig u ra tio n

R e p o rts

H elp

H elio a d m in

Log

F in d c o n te n t

My account

lo g out

Path into Drupal

Outrageous message
Mar 2i, : I am a machine for turning orange juice into Drupal patches.
Navigation
* Add content

Outrageous message

Ifcvsto* ........

. 2 7 .5 . , hook_menu_alter


. h o o k jn e n u ,
.
hook_m enu_alter,
. ,
.
Drupal-.
, .

594

27. Drupal


menu_router .

, .

,
. ,
.
Drupal. ,
.
Drupal .
, Drupal
.
,
.

28.
Drupal

Drupal
,
. Drupal
, , ,
.
, U R L -,
http://d efinitived rupa l.org /n od e/84. , U R L -
-, in d e x .p h p ? q = n o d e /8 4 .
n o d e /8 4 index.php.
- - index.php .
Drupal :
, .
Drupal .
Drupal- ronjob, hook_cron()
.
/**
* D ru p a l.

*/
d e f in e ( ' DRUPAL_ROOT', g e tc w d Q );
re q u ire _ o n ce DRUPAL_ROOT . ' / in c lu d e s / b o o t s tr a p . in c ' ;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
m e n u _ e xe cu te _ a ctive _ h a n d le r() ;

.
. n o d e /84.

,
, ,
. ,
. d r u p a l_ b o o ts tr a p ( ).
(. 28.1).
d r u p a l_ b o o t s t r a p ( ) .
2 8 .1 . Drupal

DRUPAL_BOOTSTRAP_CONFIGURATION

DRUPAL_BOOTSTRAP_PAGE_CACHE

DRUPAL_BOOTSTRAP_DATABASE

DRUPAL_BOOTSTRAP_VARIABLES

DRUPAL_BOOTSTRAP_SESSION

DRUPAL_BOOTSTRAP_PAGE_HEADER

DRUPAL_BOOTSTRAP_LANGUAGE

DRUPAL_BOOTSTRAP_FULL

596

28. Drupal

:
settings.php sites/default
.
settings.php, , , $databases,
. ,
:
$base_url. U R L -,
Drupal. .
U R L - . , Drupal
.1
$base_unl

' h ttp :/ / w w w .G x a m p le .c o m / d r u p a l';

//

$base_path. U R L - (/ - ,
) . ,
$base_url, .
$base_path

'/ d r u p a l / ';

$base_root. U R L -.
U R L - , .
$base_root

' h ttp :/ / w w w .e x a m p le .c o m ';

4& DeftnitlveDrupalorg { Code, Configuration, and Community - Mozitla Ffrefox


Fite Edit View History Bookmarks Tools Help
v ^ 7 remove from be "

http://definitjvedrupal.ofg/suggesfcions
storage... ^ O r u p a l..

<9 (drupel)..- ^ n a d e j e .,

user_en.,, ^ Entity?!,.,

Refa<to... t*O rupaL ..

# O e f ... H*

. The Definitive Guide to

Drupal 7
Code. Configuration, and Community
MTMl

Clear

Persist

URL

All

HTML. CSS

S tatu s
R esponse

XHR im ages

Domain
definitivecJrupal.org

- GET s u g g e s t io n s
Headers

css
JS

Dfwpai
Flash

Media
Size
7.1K B

Timeline
165m

Cache

R esponse Headers
D a te Wed, 1 9 Jan 2Q11 1 5 : 2 0 :1 9 GMT
S erv er A p a c h e /2 .2 .9 iO eb ia n ) n o d _ f c g i d / 2 . 3 . 6 n o d _ s s l / 2 . 2 . 9 O p en SS L /O .S.8 g W ebA uth/3.G .G
~
j g /S . 2 , 6 - 1 + te n n y 9
- D ru p a l-C e c h e

lay"1255480228-0"

X -G en erator
C ach e-C o ntro l
E x p ires
Vary
L a st-M o d ified
C o n te n t-E n c o d in g
C o n ten t-L en g th
K e ep -A liv e
C o n n e c tio n
C o n ten t-T y p e

Drupal 7 ( h t t p : / / d r u p a l . 0r 9 )
p u b l ic , m ax-age 0
Sun, 1 9 Nov 1 9 7 8 0 5 : 0 0 : 0 0 GMT
C o o kie .A c c e p t-E n c o d in g
Wed, 1 9 Jan 2011 1 5 : 1 7 : 0 8 GMT
g z ip
723 1
t ia e o u t * 1 5 , ma*=100
K e e p -A liv e
t e x t /h ts T l; c h a r s e t * u t f -8

R e q u e st H ea ders
H o st d e f i n i t i v e d r u p a l . o r g
U ser-.A gent M o n l l a / 5 . 0 ( X l l ; U; Linux 1 6 S6

v : l.9 .2 .1 3 *

G eck o /2 0 1 0 1 2 0 6 U b u n tu /1 0 .1 0 (B B verick .l F i r e f o x / 3

. 2 8 .1 . --Drupal-Cache HIT.
Firefox Firebug

1 (Jeff Eaton) (. drupal.org/


files/issues/settings.php_l. patch).

597

:

Performance
, ,
. ,
h o o k _ b o o t() h o o k _ e x it ( ).
(
$ c o n f [ ' p a g e _ c a c h e _ w ith o u t_ d a ta b a s e '] settings.php),
.

H T T P -, :
, X -D ru p a l-C a ch e HIT (. 28.1);
MISS (. 28.2).
fi

OefinitiveDrupal.org [ Code, Configuration, and Community - MoziUa Ffrefox

File Edit view History Bookmarks

* v4;:

Toois Help

: ; * ul 7 remove from bo 4

. http://defmitivedrupal.org/suggestions

; n o r a g e ... Drupal...

[drupal].., nod eje...

^ u s e r .e n ..,

EnfcityFi... <*. Re facto...

pfupal,,..

Def...

The Definitive Guide to

Drupal 7
( ode, C o n figu ratio n , and C om m u n ity

Gear

Persist

URL
- GT suggestions
M e sto s

css

OOM

mm

Ofupart

HTML CSS JS XHR images Flash Media


Status

Domain
dtfinitlvtfd rup al.o rg

Response

SI
7.1KB

1
,

396nv

CKhe

Response Headers

Dote Wed, 19 Jan 2011 15 : 17:08


Server Apache/ 2 . 2.9 (Debiani m od_fcgid/ 2 . 3.6 mod s s l / 2 . 2.9 OpenSSL/Q.9.8
J fa n n w rf By 5 . 2 . 6 - 1* 1

WebAuth/3 . 6.0

Q^rupal-Cache MISp
eU

X-Generator
Ceche-Controt
Expires
Vary
Last-Modified
Content-Encoding
Content-Length
Keep-Alive
Connection
Content-Type

T J9S 4502;'8 - 0"


Orupal 7 ( h t tp :// d r u p a l.o r g i
p u b lic . n a *-a g e 0
Sun. 19 Nov 1978 05 : 00:00 GMT
C ookie,Accept-Encoding
Wed, 19 Jan 2011 15 : 17:08 GMT
gzip

7281
tie e o u t l S . * a *97
Keep - Al i ve
te x t/h t< rt: c h a r s e t * u t f -8

Request Headers

Host d e -fin itived ru p a l .org


U s e r - A g e n t M o z illa / 5.0 1X11 .: U; Linux i

i-U S; r v : 1 . 9 . 2 . 13 } Gecko/20101206 Ubuntu/10.10 (maverick. F ir e f o x /3

* ffl*

http://deftniUvedfupal.org/

. 2 8 .2 . --Drupal-Cache MISS

. ,
Drupal . ,
$conf[cache_backends]. ,
DrupalCachelnterface. Drupal
, .
memcache (drupal.org/project/memcache),
memcached ( 26).
, Varnish (www.vamish-cache.org/),
,

&

598

28. Drupal

hook_boot() hook_exit(). ,
, , .
settings.php 1:
$ c o n f[ 'page_cache_invoke_hooks' ] = FALSE;
i f ( !c la s s _ e x is ts ('D ru p a lF a k e C a c h e ') ) {
$ c o n f[ ' cache_backends'] [ ]

= ' in c lu d e s / c a c h e - in s t a ll. in c ' ;

}
/ /
$ c o n f[ ' cache_class_cache_page'] = 'D rup alF a keC a che ';

:
.
, (db _q uery
. .). , Standard
Library (SPL) 2.
.info
include, Drupal .
,
.

Drupal 7 .
( ) , db_query()
PDO 5: ,
, , ,
/.
db_query(). .

Drupal (
, )
$ c o n f ,
settings.php. , $ c o n f ['v a ria b le _ n a m e '],
; ,
UI, settings.php.
$ c o n f .
v a r ia b le _ g e t ( 'k e y _ n a m e ', 'a d e f a u l t v a lu e ).
, v a r ia b le _ s e t ( ' key_nam e' , ' v a lu e ' ) .
, ,
h o o k _ b o o t() , h o o k _ e x it ( ) , h o o k _ la n g u a g e _ in it ( ) h o o k _ w a tc h d o g ( ).
. ,
. Drupal ,
$ c o n f [ ' lo c k _ in c ' ] = p a t h / t o / y o u r / lo c k , i n c ' .
.
1 . http://drupal.org/node/797346.
2 . http://php.net/manual/en/function.spl-autoload-register.php.

599

Drupal : Drupal
. ,
, , ,
.
, .
.
,
Drupal 7 .
. .
.
, ;
. ,
. ,
,
. http://api.Drupal.org/api/
Drupal/includes--lock.inc/group/lock/7.

:
, , , ,
Drupal , .
Drupal ,
.
, , , -
$_SESSION; .
H T T P - . Drupal
, , Drupal
.
,
, $[' c o n f '] [ ' s e s s io n _ in c '] settings.php
, .
.
, , 26 Mongodb.

:

: H T T P -. , Drupal
, . ,
, Drupal .
, ,
. ! - :
h o o k _ b o o t( ),
.
(. 3).

:

.
h o o k _ la n g u a g e _ in it( ) , , .

600

28. Drupal


, , ,
h o o k _ la n g u a g e _ n e g o tia tio n _ in fo ( ), hook_lan gu ag e_
n e g o t i a t i o n _ i n f o _ a l t e r ( ) . ,
a d m in /c o n fig /
regional/language/configure.
. ,
.
:
$providers[LOCALE_LANGUAGE_NEGOTIATION_URL] = a r r a y (
ty p e s ' => r a y ( LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE,
LANGUAGE_TYPE_URL),
'c a llb a c k s ' => a rra y (
'la n g u a g e ' => ' lo c a le _ la n g u a g e _ fro m _ u rl' ,
's w itc h e r ' => ' lo c a le _ la n g u a g e _ s w itc h e r_ u rl' ,
'u r l_ r e w r it e ' => ' lo c a le _ la n g u a g e _ u r l_ re w r ite _ u rl' ,

)s
' f i l e ' => $ f i l e ,
'w e ig h t' => -8 j
'name' => t( 'U R L ' ),
'd e s c r ip t io n ' => t( 'D e te r m in e th e language from th e URL (
Path p r e f ix o r d o m a in ).' ) ,
'c o n f ig ' => ' a d m in /c o n fig /r e g io n a l/la n g u a g e /c o n fig u r e /u r l' ,

);

:

d r u p a l_ b o o t s t r a p _ f u l l ( ). ,
Drupal. (
.m odule). h o o k _ s tre a m _ w ra p p e rs ( )
1,
h o o k _ s tre a m _ w ra p p e r_ a lte r() . , ,
, , .
$_G ET[ 'q ] , .

Drupal ,
, menu.inc path.inc
settings.php. Drupal.
,
Drupal.

d ru p a l_ g e t_ n o rm a l_ p a th ( ). ,
$_G ET['q']
U R L -, U R L - (n o d e /8 4 ,
use / 123). ,
h o o k _ u r l_ in b o u n d _ a lte r ( ) . ,
1 . http://api.drupal.Org/api/drupal/modules--system--system.api.php/function/hook_url_inbound_alter/7.

601

U R L - .
API.
. ,
UI, , ,
, hook_custom _them e( ), ,
. CSS- JavaScript, .info , , h o o k _ in i t ( ),
.
, Drupal ,
h o o k _ in it ( ). API :
,
. Locale h o o k _ in i t ( )
.

Drupal 6 hook_init() CSS- JavaScript-,


. -
, .info , :
scripts[] = example.js stylesheets[all][] = example.css.
hook_init() system_init().


Drupal ,
. .htaccess index.php,
Drupal U R L - ,
.
. ,
.
27. ,
.
Drupal :
;
m e n u _ ro u te r ;
;
, .
, H T T P -,
, d r u p a l_ r e n d e r ( ) .
d ru p a l_ d e liv e r_ p a g e ( ),
. d ru p a l_ d e liv e r _ h tm l_ p a g e ( ).
d r u p a l_ r e n d e r O ,
,
H T M L .
. 28.3.

602

28. Drupal


>

hook_bootO

>
'
/

hook_exitO

hook_language_initO
hook_stream_wrappers
hook_stream_wrappers_alterO
hook_url_inbound_alterO
hook_custom_themeO
hookJnitQ

hook_menu_site_status_alterO
hook_menu_get_item_alterO
hook_page_delivery_callback_alterO
hook_page_buildO
hook_page_alterO

hook_exitQ

. 2 8 .3 .


node/84, .
Drupal , 84, node_
lo a d ( 8 4 ) . D r u p a lD e f a u lt E n t i t y C o n t r o lle r

603

N o d e C o n tr o lle r
h o o k _ lo a d ( ), h o o k _ e n tity _ lo a d ( ) h o o k _ n o d e _ lo a d ( ),
.
fie ld _ _ a t t a c h _ lo a d ( ) . ,
h o o k _ fie ld _ s to r a g e _ p r e _ lo a d ( ) h o o k _ fie ld _ a tt a c h _ lo a d ( ) ,
. 84 book book
. 28.4
. , .
m
^

Name
* 843

(
# ClASSNAME
b cri---- -------- - ------- -...................-....

..... -...- - - .....

tel

uid

title
/ 4> tog

.......- ............

........ -

stdClass

345
r

!i
|

Value

Tvpe

.........
......

.....

Under the Hood

\
\

status
comment

;1

promote
sticky

;0

# nid
language

;Q
84

created

book
und
;1278377331

|ai

chan^d

L* o

translate
W

1294971816

[ o .. .

tnid
revisionAimestamp

1294971816

..

V revlsiwjiid

17
IS*!............. ...........................

rdf__ntity_load(X
bookunode.

comment_nodejoad0

1278377331

"
Benjamin MelanvRon

i
user_node_load 5ldCfass
.

_________ ______________ ____ ______ ___ ____ ____

. 2 8 .4 . Netbeans

bo o k_ n o d e _ lo a d ( ),
ho ok_ no de_ lo ad( ) book. ,
, . ,
, ,
, . ,
. , ,
.
.
/**
* ho ok_ n o d e _ lo a d ().

*/
fu n c tio n book_node_load($nodes, $ ty p e s ) {
$r e s u lt = db__query("SELECT * FROM {b o o k} b INNER JOIN {m e n u _ lin k s } ml ON \
b .m lid = m l.m lid WHERE b .n id IN ( : n id s ) " , a r r a y ( ' : n id s ' => \
a rra y _ k e y s ( $nodes) ) ,

&

604

28. Drupal

( ' f e t c h ' => PDO::FETCH_ASSOC));


fo re a ch ( $ r e s u lt as $ re c o rd ) {
$ n o d e s [$ re c o rd [' n i d ' ] ]->book = $ re c o rd ;
$ n o d e s [$ re c o rd [' n i d ' ] ]- > b o o k [' h r e f ' ] = $ r e c o r d [' lin k _ p a t h ' ] ;
$ n o d e s [$ r e c o r d ['n id ']]- > b o o k [, t i t l e ' ] = $ r e c o r d [ ' l i n k _ t i t l e ' ] ;
$ n o d e s [$ re c o rd [' n i d ' ] ] -> b o o k [' o p tio n s ' ] =
u n s e r ia liz e ( $ r e c o r d ['o p tio n s ' ] ) ;

}
}


n o d e _ p a g e _ vie w ( ).
1 head ( )
H T T P -. nod^_show (),
no d e _ _ vie w _ m u ltip le ( ).
n o d e _ v ie w ().
,
h o o k _ e n tity _ p r e p a r e _ v ie w ( ). ;
,
E N T IT Y _ b u ild _ c o n te n t() E N T IT Y _ v ie w _ m u ltip le ( ).
e n t it y _ p r e p a r e _ v ie w ( ) , n o d e _ v ie w _ m u ltip le ( ).
API e n tity _ p r e p a r e _ v ie w ( )2.
( )
n o d e _ v ie w (), node_
b u ild _ c o n t e n t( ). .
h o o k _ e n tity _ v ie w ( )
h o o k _ n o d e _ v ie w (). book ,
book navigation, . 28.5.
. 28.6.
h o o k _ e n t it y _ v ie w _ a lt e r ( ) h o o k _ n o d e _ v ie w _ a lte r()
.

d r u p a l_ d e liv e r _ p a g e ( ),
d r u p a l_ d e liv e r _ h tm l_ p a g e ( ) . ,
h o o k _ p a g e _ b u ild () h o o k _ p a g e _ a lte r( ) , d r u p a l_ r e n d e r ( )
, . h o o k _ p a g e _ b u ild ( )
block . b o o k _ p a g e _ a lte r( ),
h o o k _ p a g e _ a lte r (),
.
/**
* h o o k _ p a g e _ a lte r() .

*
* book,
* .

*/
fu n c tio n book_page_alter(& $page) {

1
URL-. URL, SMS-.
2 . api.drupal.org/api/drupal/includes--common.inc/function/entity_prepare_view/7.

if

(($node = m e n u _ g e t_ o b je c t()) && ! em pty($node->book[ ' b i d ' ] ) )


$active_m enus = menu_get_active_menu_names ( ) ;
$ a ctive _ m e n u s[] = $node->book['m enu_nam e'] ;
menu_set_active_m enu_nam es($active_m enus);

605


. , ,
. 28.7.

N etBeans I &.*). I

if

<default>

^^^
- ;]:- *

7*9
800
S01
802

304
805
806
80 /
808
809

|
;
|
|
|

'<

i f

I/'

'

S a n c t i o n b o o k _ n o d e _ v i o w ( ? n o d e , S v i e w mo d e ) {
i f ( tv lB b \p a d e *
) {
if (
{
: . ) ) i t , e s \p c y ( S n o d e - >
$ n o d e -> . .
[

..
*> th e m e ( .
fin , a r r a y (
-v .
*> 100 ,
);
>
>

811
if

St-

813
814
815
816
81 ?
818

( $ v i W .,K K te J*
i'a .s ) (
b o o k n o d e v ie w lin J c ( ? n o d e ,

$ v ie w _ i$ o d e ) ;

}
)

...
B re a k p o in ts

W''
?
m

Value

<p !ast_comment_timestamp

1278377331

last_comment_uid

comment_count

0
Benjamin.M elanvRon

. name

picture

sidClass

CLASSNAME

a :l:{s:8 ',gravatar;i:l:]'

data
- uri
entityj/iew_prepared

content

> {body}
* Q [fieldjmage]
<v [#pre_render]
f*entity_typej

node

l*bundtej

book

* Q [jinks]_______
V- [book_navigationj''"-v.

[#rnarkup]

TjnocfF

<dtv id"book-navigatjon~SO" class="b..


100

(^weight)

full
netbeans-xdebug

running

812 | 1

INS

. 2 8 .5 . 84 , book_node_view()

606

28. Drupal

. 2 8 .6 .

hookJoadO
hook_entityjoad0
hook_nodejoad0
hook_field_storage_pre_loadO
hook_field_attach_load
hook_entity_viewO
hook_node_view()
hook_entity_view_alterO
hook_node_view_alterQ

hook_page_buildO
hook_page_alterQ

. 28.7.

607

Drupal,
. ,
. .

. Drupal-
, ,
, .
; ,
, ,
.

Drupal 7 ,
. ,
.
.
, ,
.
. ,
; ,

. ,
Drupal-.
Drupal
dgd7.org/inside.

29. Apache Solr


Search Integration

Apache Solr Search Integration,


, Search Drupal,
, .
, .
Drupal -
- .
Search Drupal API ,
. Search
.
Search. Drupal
Node User.
Node .
Drupal, S Q L - .
,

. , (
,
), .
Apache Solr Search Integration (drupal.org/project/apachesolr)
Node .
, Solr- Drupal.
API Search Drupal 7 ,
Apache Solr Search Integration Search
Drupal 6. , Node:

Facet API;

, ;
,
;
( 10 );
, ,
, ,
.

(facet) (
), . ,
.

Apache Solr Lucene Java.


Lucene , .
H T T P - Apache Solr Drupal (
) , .
Solr
Drupal-:

Apache Solr Search Integration

609


. Solr
-, ; ,
,
. Drupal-
Solr 1.4.x, .
Solr:
.
VPS. Solr Java (, Jetty Tomcat) ,
H T T P - .
Solr-. ,
Drupal, Solr- Acquia.
.
,
May First People Link.
A
Dashboard

Content

Structure

Add content

Find content

Appearance

People

Modules

Configuration

Reports

Configure how content input by users :s filtered, including allowed HTML


tags. Also allows enabling of module-provided filters.
USER INI
MEDIA
Shot
Add

jfjj File system


Tell Drupal where to store uploaded files and how they are accessed.
jjjj image styles
Configure styles that can be used for resizing or adjusting images on
display.
Image toolkit
Choose which image toolkit to use if you have installed optional toolkits.

DEVELOf
jj

F(rf
Enafc
banc

|} Log<
SEARCH AND METADATA

Setti
Druf

Search settings
Configure relevance settings for sea rch ed other indexing options.

Matt
Take

Apache Solr search


Administer Apache Soir.

Test
Run
assu

URL aliases
Change your site s URL paths by aliasing them.
Clean URLs
Enable or disable clean URLs for your sire.

WEB SER'
RSS
Conl
feed

REGIONAL AND LANGUAGE

. 2 9 .1 .

610

29. Apache Solr Search Integration

Apache Solr Jetty,



. README.txt Apache Solr Search Integration.
,
Solr .


D ru p a l 7 Search
. (Search
Apache Solr Search Integration) Search and metadata adm in/
config, . 29.1.
Search settings I drupai-7.dev
http://drupal-7.dev/adm in/config/search/settin9s

&
A

Dashboard

Add content

Content

Structure ' Appearance

People

Modules

Configuration

Find content

been . ..

The default settings should be appropriate for the majority of sites.


Minimum word length to index

.....
The number of characters a word has to be to be indexed. A lower setting means better s<
Each search query must contain at feast one keyword that is this size (or longer),
(3$ Simple CjK handling

Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping s<


external preprocessor for this instead. Does not affect other languages,

ACTIVE SEARCH MODULES

Apache Solr search


Node
0 User

Choose which search modules are active from the available modules.

Default search m odule,

Apache Solr search

Node
0 User

Choose which search module is the default.

Save configuration

. 2 9 .2 . Search

Apache Soir Search Integration

611

Search, . 29.2,
adm in/config/search/settings ,
. ,
( ).
Apache Soir Search Integration,
Node, , . 29.2.


.
,
,
, , , , ,
. ,
, .
, .
( JavaScript).
Retain current filters, . 29.3.
, .
Search Site soir * Article
Current search
Search found 3 items
$5 soir
@3Article

Navigation

soir

Q.

G Retain current filters

Search results
more about Soir
Apache Soir is its own open-source project; actually a part of the
Lucene Java project where Lueene is the actual search library that
Soir is built upon. Apache Soir provides a HTTP... on the same
server, or a totally separate server. The fact that Soir can be run on
a separate server is one...

Sort by
Relcvancy
Title
Type
Author
Date

Kilter by author
yyy * 12/19/20x0 - 21:04 * comments

Qm&)

CJpeter(i)
Introduction section
or taxonomy term via the advanced search form) this is rath
limited. The Apache Soir Search Integration ... content. A Wma
range of content indexing and filtering functionality is available, and
Soir server can... in Drupal 7 were driven by the limitations that
were encountered creating Apache Soir Search Integration ...

Filter by type
Article

yyy - 12/19/20io - 21:11 - o comments

O soir(3)
Hooks implementations

module {2,j
search ()

. 2 9 .3 . ,

612

29. Apache Solr Search Integration

API Search
Search Drupal .
,
.
search.api.php,
Search Drupal 7;
api.drupal.org. , Apache Solr Search
Integration. ,
.


,
. ,
, API.
h o o k _ s e a rc h _ in fo ()
hook_ sea rch _e xecu te ()

. h o o k _ s e a rc h _ in f ( )
Search :
,
( ) ,
, . , h o o k _ s e a rc h _ e x e c u te ( ),
,
. , P O S T
U R L -.
U R L -
. h o o k _ s e a rc h _ e x e c u te ( ) ,
/,
.

, URL- GET,
. , Drupal URL-
,
.

Search
,
,
Search :
hook_search_access()
h o o k_ se a rch _ re se t()
h o o k _ se a rch _ sta tu s()
hook_sea rch_adm in( )
hook_search_page()
ho ok_ sea rch _p rep rocess()
ho ok_update_index( )

h o o k _ s e a rc h _ p a g e ( ),
.

API Search

613

h o o k _ s e a rc h _ e x e c u te ( ) .
29.1 ,
.
Apache Solr Search Integration ,
, h o o k _ s e a rc h _ in fo () .

.
Search , Apache Solr Search Integration. ,
h o o k _ s e a rc h _ in fo ( )
,
.
h o o k _ m e n u _ a lte r().

2 9 .1 . Search
/**
* h o o k _ s e a rc h _ in fo ()

*/
fu n c tio n a p a c h e s o lr_ s e a rc h _ s e a rc h _ in fo () {
re tu r n v a ria b le _ g e t('a p a c h e s o lr_ s e a rc h _ s e a rc h _ in fo ', a rra y (
' t i t l e ' => ' S i t e ' ,
'p a t h ' => ' s i t e ' ,
' c o n d itio n s _ c a llb a c k ' => ' a p a c h e s o lr_ s e a rc h _ c o n d itio n s ' ,

) );
}
/**
* hook__search_execute()

*/
fu n c tio n a p a ch eso lr_se arch_ sea rch_ execu te (
$keys = NULL, $ c o n d itio n s = NULL) {
$ f i l t e r s = i s s e t ( $ c o n d i t i o n s [ ' f i l t e r s ' ] ) ? $ c o n d i t i o n s [ 'f i l t e r s ' ]
$ s o lr s o r t = is s e t( $ _ G E T ['s o lr s o r t ' ] ) ? $_GET[' s o l r s o r t ' ] : ' ' ;
try {
re tu r n a p a ch e so lr_ se a rch _ ru n (
$keys, $ f i l t e r s , $ s o lr s o r t , 's e a r c h /' . a r g ( l ) ,
p a g e r_ fin d _ p a g e ( ) ) j

: '

}
ca tc h (E x c e p tio n $e) {
watchdog('Apache S o l r ', n l2 b r(
c h e c k _ p la in ($ e -> g e tM e s s a g e ())) , NULL, WATCHDOG_ERROR);
a p a c h e s o lr _ f a ilu r e ( t ( ' S o lr s e a r c h ') , $ ke ys);

}
}
/**
* se a rc h _ v ie w ()

*/
fu n c tio n a p a ch e so lr_ _ se a rch _ co n d itio n s() {
$ c o n d itio n s = a r r a y ( ) ;
i f ( is s e t ( $ _ G E T [ 'f ilt e r s ' ] ) && t r im ( $ _ G E T [ 'f il t e r s '] ) ) {
$ c o n d i t i o n s [ 'f i l t e r s ' ] = trim ($ _ G E T [' f i l t e r s ' ] ) ;

>
if

(v a ria b le _ g e t('a p a c h e s o lr_ s e a rc h _ b ro w s e ', 'b ro w s e ') == r e s u l t s ') {


/ / , .
$ c o n d itio n s ['a p a c h e s o lr_ s e a rc h _ b ro w s e '] - ' r e s u l t s ' ;

&

614

29. Apache Solr Search Integration

29.1 ()
r e tu rn $ c o n d itio n s j

}
/**
* h o o k _ s e a rc h _ re s e t()

*/
fu n c tio n a p a c h e s o lr_ s e a rc h _ s e a rc h _ re s e t(){
a p a c h e s o lr_ c le a r_ la s t_ in d e x ('a p a c h e s o lr_ s e a rc h ' ) ;

}
/**
* h o o k _ s e a rc h _ s ta tu s ().

*/
fu n c tio n a p a c h e s o lr_ s e a rc h _ s e a rc h _ s ta tu s () {
re tu rn a p a c h e s o lr_ in d e x _ s ta tu s ( ' a p a c h e s o lr_ s e a rc h ' ) ;

>
/**
* hook_search_page()

*/
fu n c tio n a p a ch e so lr_ se a rch _ se a rch _ p a g e ($ re su lts) {
i f ( ! e m p ty ( $ r e s u lts [' apach eso lr_se arch_ bro w se' ] ) )
/ / .
$ o u tp u t = apachesolr_search_page_browse(
$ r e s u lt s [ ' ap achesolr_search_brow se' ] ) ;

>
e l s e i f ( $ r e s u lt s ) {
$ o u tp u t = a rra y (
'#them e' => ' s e a rc h _ re s u lts ' ,
'# r e s u lt s ' => $ r e s u lts ,
'tm o d u le ' => ' a p a ch e so lr_ se a rch ' ,

);
>
e ls e {
/ /
$ o u tp u t = a rra y ('# m a rk u p ' => th e m e ('a p a c h e s o lr_ s e a rc h _ n o re s u lts ') ) ;

}
r e tu rn $ o u tp u t;

,
; h o o k _ s e a rc h _ s ta tu s ( ) hook__search_reset( )
, Search
Apache Solr Search Integration. , h o o k_ se a rch _
p a g e (), , , ,
.
Search.

Apache Solr Search


Apache Solr Search Integration
, .
,
, ,
, .

Apache Solr Search

615


,
. -,
Apache Solr Search Integration,
Block. Solr-
.
, . ,
Tags, ,
. 29.4, .
. ArimteiiratwSft *Configuration * S e a s * and metadata * Apart*# search
Apache Solr search

MMX

stHHics

* .

KlCtIK

Settings for: iocaihost server


The Blocks re a lm d isp lay s e a ch facet in a se p a ra te . U sers a re able to refine their se arc h es in a d rill-d o w n fashion.
For p e rfo rm a n c e re a s o n s , you sh o u ld only en a b le fa c e ts th a t you in te n d to have available to u se rs o n th e sea rch p age.
f)how row w egbts

FACET

A*. *4

OPERATIONS

Content type
.

td*t

Export

edit

Export

Tags

Wftir fey fieid of ty pe taxonom yjcm .rtfereftc*.

Rating

U"'
:+

FiHer bv field of type iist_X't.

Author
Filter by author.

Edit

Updated date

&tpon

fxfxm

Fitter by the daw the node was tast modJfutfi.


L an g u a g e

; -b

; 4*

FMter by language.

Edit

Export

Edit

Export

Post date
Finer by the sate the notie was posted.

S av e c o n f ig u r a tio n

. 2 9 .4 .



, , . ,
. , ,
, .
. Basic page type content
bias , Ignore, ,

. , , .
, ,
, .

, . 29.5.

616

29. Apache Solr Search Integration

,
.
TYPE BIASING AND EXCLUSION
Article type copfe n t bias______
20

-J

-----------------------------------

Basic page type content bias


Igcore rj
Specify here which node types should get a higher relevancy score in searches. Any value except ignore will increase the score o f the
given type in search results,

Types to exclude from the search index


Article
Q Basic page
Specify' here which node types should he totally exclu d ed from the search index. Content exclu d e d from the in d ex will never ap p e ar in
any search resu lts.

Save configuration

Reset to defaults

. 2 9.5.

Apache Solr Search


Apache Solr Search ,
Drupal.

, , ,
Drupal.org . ,
apachesolr.api.php,
.

Solr
Apache Solr Search Integration
. , , ,
.
h o o ^ a p a c h e s o l^ u p d a te ^ n d e x C J d o c u m e n t, $ e n t it y , $namespace).
Solr,
, Apache Solr Search Integration
. ,
, .
Solr schema.xml
.
. ,
:
fu n c tio n
if

M YM O D U LE_ap ach esolr_u p da te_ind ex($docu m en tj

($n o d e->typ e

==

site_p ro d u ct

$node,

$n am espace){

&& $ d o c u m e n t - > e n t i t y _ t y p e

/ / .

==

'n o d e ')

Apache Solr Search

617

$ d o cu m e n t-> fs_ p rice = $ n o d e -> p ric e ;

}
>

.
,
. hook_no de_ vie w ($n od e, $view_mode, $ la n g c o d e )
$view_mode .
h o o k _ n o d e _ u p d a te _ in d e x ($ n o d e ).
. ,
,
.
Drupal 7 Fields API.
Apache Solr Search Integration
() ,
.
(Content Construction Kit) 6.-2.; 7.x
, .
Solr-
l i s t (, l i s t _ t e x t ) .
h o o k _ a p a c h e s o lr_ fie ld _ m a p p in g s _ a lte r(& $ m a p p in g s ).
apachesolr.api.php.
.
, ,
.
h o o k _ a p a c h e s o lr_ n o d e _ e x c lu d e ($ n o d e , Jnam espace).
- TRUE, .


Solr ,
. ,
h o o k _ a p a c h e s o lr_
u p d a te _ in d e x ($ d o c u m e n t, $node, Jnam espace). ,
, ,
. . ho o k_ a p a ch e so lr_ m o d ify_ q u e ry ($ q u e ry ,
$ c a l l e r ) f l , Solr, :
fu n c tio n MYMODULE_apachesolr_query_alter($query){
/ / .
$query->addP aram (' f 1 ', ' f s _ p r ic e ' ) ;

h o o k _ a p a c h e s o lr_ m o d ify _ q u e ry ()
, . , ,
Apache Solr.
, n o d e _ a c c e s s _ g ra n ts ( ).
h o o k _ a p a c h e s o lr_ u p d a te _ in d e x ( ),
Solr-
.
h o o k _ a p a c h e s o lr_ q u e ry _ p re p a re ( $ q u e r y ).
,
h o o k _ a p a c h e s o lr_ q u e ry _ a lte r( ) .

618

29. Apache Solr Search Integration

( ),
.
h o o k _ a p a c h e s o lr_ s e a rc h _ re s u lt_ a lte r($ d o c , $ e x tra ),
.

Apache Solr
, Search Apache Solr Search
Integration , , ,
Apache Solr. Drupal Solr- H T T P -,
d r u p a l_ h ttp _ r e q u e s t (
, , c u r l f ile _ g e t _ c o n t e n t s ( ),
). Solr , R E S T -. ,
, 1.4.x H T T P - ,
, R E S T -.
URL- (
); POST,
GET.

Solr-. code.google.com /p/solr-php-client.
Apache Solr Search Integration
, .
f ile _ g e t _ c o n t e n t s ( ) D r u p a lJ r tt p _ r e q u e s tQ ,
Drupal. D ru p a lA p a c h e S o lrS e rv ic e ,
A p a ch e _ S o lr_ S e rvice .
.

Solr-
Solr- X M L - P O S T
/up date Solr-. ,
. Solr

DOIN. N o S Q L - ,
, MongoDB.
, .
P O S T X M L -,
, , , .


U R L - .

, - .
- , , Solr- .
URL-
Solr. ,
schema.xml, ,
. Solr ,
, Jetty h ttp ://lo ca lh o st:8 9 8 3 /so lr/a d m in /.

619

. 29.6. ,
, ,
.

Solr Admin (drupal-7.1.0)


10.19.128.78:8983

cwd*

Apache

Solr *

iiii

!-1.4.1/ SolrHomc^solf/

Solr

[ s c h e m a ] [ c o n f ig ] [ANALYSIS] [ s c h em a b r o w s e r ]
[ s t a t i s t i c s ] [ in f o j io is t r ib u t io n ] [ p in g ] [ lo g g in g ]

App server:

[ ja v a p r o p e r t ie s ] [ threao dum p ]

....... ' ..... ...............

.....

Make a Query

[ f u l l in te r f a c e ]

Query String:

aolr~*

Assistance

[d o cu m en tatio n ] [issu e t r a c k e r ] [sen d em ail]


[ so l r q u er y s y n t a x ]

Current Time: Sun Jan 02 14:21:58 EST 2011

'

........:

Server Start At: Sun Jan 02 14:21:34 EST 2011

; .

............ -

. 2 9 .6 . Apache Solr

Apache Solr Search Integration


.
.
Apache Solr Search Integration Drupal 7
,
, Views.

dgd7.org/solr.

30. :
90 %

: , ,
.
, , , (
, 1). , .
(. 8). (. 15 16).
, 90 %. 10 %
. ,
, .
,
, .
,
,
DefinitiveDrupal.org . (
, ;
21.) ,
,
Drupal.org.
.
15 16, ,
DefinitiveDrupal.org. (Jacine Luisi).
( . dgd7.org/them e and dg d7.org/code).


dgd7.org/other90.


(view modes), Drupal 6 (build modes),
8.
. DefinitiveDrupal.org
Full Content (
Default). Teaser.
, , .
. 30.1
dgd7glue.m odule; (Benjamin
Doherty), Drupal Camp
GitHub github.com /bangpound/fldrupalcam p-dem o.
; ,
h o o k _ e n t it y _ in f o _ a lt e r ( ) , ,
, .
3 0 .1 . Compact
<?php

/**

621

* h o o k _ e n tity _ in f o _ a lte r ( ) .

* node.
* "manage d is p la y " F ie ld U I,
* .

*/
fu n c tio n d g d 7 g lu e _ e n tity _ in fo _ a lte r ( & $ e n tity _ in fo ) {
$ e n t it y _ i n f o [ ' n o d e '] [ 'v ie w modes' ] [ ' com pact' ] = a r r a y (
'l a b e l ' => t('C o m p a c t1) ,
'custom s e t t in g s ' => FALSE,

);
}
/**
* hook_preprocess_node() .

* .

*/
f u n c tio n dgd7glue_preprocess_node(& $vars) {
$view_mode = $ v a r s [ ' view_mode' ] ;
$ v a r s ['c la s s e s _ a r r a y ' ] [ ] = 'n o d e -' . $view_mode;
$type = $ v a r s [ 't y p e '] ;
$ v a rs ['th e m e _ h o o k _ s u g g e s tio n s ' ] [ ] = 'node__' . $type . ' __ 1 . $view_mode;

, h o o k _ p r e p ro c e s s _ n o d e ( ),
,
. , 'c la s s e s _ a rr a y ' CSS-
, Compact, node-com pact.
1th e m e _ h o o k _ s u g g e s tio n s '
node.tpl.php node--profilecom pact.tpl.php , , nodearticle--teaser,
tpl.php , Compact
Teaser. ,
, .

hook_preprocess_node() template.php,
.


.
h o o k _ p re p ro c e s s _ n o d e ( )
d e b u g (),
Devel Krumo
, k p r ().
k p r ( $ v a r s ) h o o k _ p re p ro c e s s _ n o d e ( )
,
. , k p r ( )
Devel.
. , , ,
.
h o o k _ p re p ro c e s s _ n o d e () (, $ v a rs [ 'c u r r e n t _ t im e '] =
d a te ( 'YM d H :m :s ',t i m e ( ) ) ; ) node.tpl.php ( ,
nodearticle.tpl.php nodearticleteaser.tpl.php)

622

30. : 90 %

$ c u r re n t_ tim e . p r i n t $ c u r r e n t_ tim e ;
p r i n t re n d e r ({c o m p le x );.
.

30.1 dgd7glue.module,
dgd7glue, sites/all/modules/custom/.
.info, , dgd7glue.info ( 30.2),
dgd7glue. 17 19,
21.
3 0 .2 . dgd7glue.info
name = DGD7 Glue Code
d e s c r ip tio n = [d g d 7 g lu e ] S it e - s p e c if ic custom code f o r D e fin it iv e D r u p a l.o r g .
package = Custom
v e rs io n = 7 .X -1 .0
core = 7 .x

version ,
Drupal.org;
.

, DGD7glue, ,
( ), .
Structure Content types Author
profile Manage display (adm in/structure/types/m anage/profile/display). Custom
display settings Compact, . 30.1.
'CUSTOM DISPLAY SETTINGS
Use custom display settings for the following view m odes
Q Full content
Teaser

QRSS
0 Search index
Q Search result

Mnt

UJCompact

Save

. 3 0 .1 .
Compact

,
( Teaser), $entity_in fo['n ode']
[View modes'] ['viewmodename'] xyK ahook_entity_info_alter() custom settings'
=> TRUE . ,
.

623

Compact, . 30.2,
, Compact.
, ,
Drupal.org ,
300 . .

Teaser

Compact

. 3 0 .2 . Manage display Compact

Chapter .
Compact,
Author Compact
. Author
, , , Title (link),
Title (no link), Rendered node <Hidden>. Rendered node
, ,
, Author.
Compact , . 30.3.



,
. , ,
.
, n o d e -p ro file .tp l.p h p ( profile
Author profile).
, ,
.

624

30. : 90 %

1. node.tpl.php (
templates). Drupal
.
2. node.tpl.php,
.
node_content_type_view_mode.
, nodecontenttype view-mode.tpl.php. Compact
node profile compact.tpl.php.
3. .

Drupal 7 (
). Drupal 6 ,
nodecontent-type--view-mode.tpl.php.
, .

30.3 (
node.tpl.php api.
drupal.org/api/modules--node--node.tpl.php). ,
node-profile-compact.tpl.php. templates.
, .
.

30.3 , Devel,
, , Drupal,
debug(), PHP- print_r(). dpm() Devel, debug()
Drupal. kpr() Devel,
PHP- print_r() , ,
.
3 0 .3 . ,
Compact
<?php
k p r($ c o n te n t);

?>
< d iv id="node-<?php p r i n t $ n od e-> nid ; ?>" class="<?php
p r i n t $ c la s s e s ; ?> c le a rfix " < ? p h p p r i n t $ a t t r ib u t e s ; ?>>
<?php p r i n t r e n d e r ( $ c o n te n t['fie ld _ im a g e '] ) ; ?>
< d iv c la s s = " a u th o r-in fo " >
<h3<?php p r i n t $ t i t l e _ a t t r i b u t e s ; ?>><a hre f= "< ?p hp
p r i n t $ n o d e _ u rlj ?>"><?php p r i n t $ t i t l e ; ? > < /a x /h 3 >
<?php
/ / .
h id e ($ c o n te n t['c o m m e n ts '] ) ;
h i d e ( $ c o n t e n t [ 'l in k s '] ) ;
p r i n t re n d e r($ c o n te n t);

?>
< /d iv >
< /d iv >

, div,
, (

625

) print render($content['field_image']);.
render () .
15 16.
H T M L -, 30.3, CSS-,
30.4
Firebug (. getfirebug.com).
3 0 .4 . style.css Theme,

/**
* .

*/
.node-com pact . f i e l d
padding: 0;

}
.node-com pact .fie ld - n a m e - fie ld - im a g e {
p o s it io n : a b s o lu te ;

>
.node-com pact . a u th o r - in fo {
m a r g in - le f t : 130px;

>

, .node div
position: relative. ,
. 30.4.
&
Drupal.org user ID: mlncn
Benjamin builds web sites to give people a little more power over their online
presence. He strives to build ways to connect people for planning and
coordination that will help us all gain a lot more power in the rest of our lives.

Dan Hakimzadeh
Drupal.org user ID: dhakimzadeh
As co-founder of Agaric, Dan spends his time and energy building on this mystical
phenomenon popularly called the Internet. He believes in the principles of free
open source software and develops primarily using the Drupal content
management framework.

. 3 0 .4 .
Compact CSS-

; ,
- . : CSS-,
Drupal
.

, CSS- (
),
, ,
. 15 16,

626

30. : 90 %

them e_node__s u g g e s tio n ( ) node--suggestion.tpl.


php, h o o k _ p re p ro c e s s _ n o d e __s u g g e s tio n .

h o o k _ p re p ro c e s s _ n o d e (), ,
( $ v a rs [ 't y p e ']) ( $ v a rs ['v ie w jn o d e ']), ,
- . , $ v a rs
{ v a r i a b le s . ,
h o o k _ p re p ro c e s s _ n o d e ().
h o o k _ p re p ro c e s s _ p a g e (), h o ok_ prep roce ss_co m m e nt() . . ,
15 16, , .

30.3 ,
div field, field-items field-item.
: CSS- ,
, . ,
. , hook_preprocess_node()
, ,
hook_preprocess_field(). . dgd7.org/222.


,
. Chapter number/Appendix letter
. Drupal
( ; . dgd7.org/226),
,
Chapter 1 . . .
, API- (, te m p la te _
p r e p r o c e s s _ f ie ld ( )),
hook_preprocess_H O O K(), d g d 7 g lu e _ p r e p r o c e s s _ fie ld ( ) ,
.

hook_process_
() (. api.drupal.org/hook_process_HOOK)
API.

tem plate.php
; , ( 30.5).
3 0 .5 . hook_preprocess_field() Krumo
fu n c tio n d g d 7 g lu e _ p re p ro c e s s _ fie ld (& $ v a rs ) {
k p r($ v a rs ) ;

, Drupal, debug()
dpm() Devel,
. ,
,
print_r(), krumo() (
Devel). 30.5 kpr()
- .

627

krumo kpr() Devel ,


.
;
. . 30.5 ele m e n t;
, # fie ld _ n a m e ,
#view__mode # b u n d le . e le m e n t
Render API ,
, .
.

; , ,
29.
$ v a r s [ 'it e m s ' ] [ 0 ] [ '# m a rk u p ' ].
... (Array, 8 elements)
element (Array, 17 elements)
#theme (String. 5 characters) flehl
#weight (String, 1 characters) 0
#tltie (String. 14 characters) Chapter number
#access (Boolean) TRUE
#labet, display (String. 6 characters) hidden

#vlew mode (String. 4 characters) fuH


la n g u a g e (String. 3 characters) und

#fleld. name (String. 12 characters) field, number


#fleftd type (String, 4 characters} text
tffleld translatable (String, J characters) 1
#entity_ type (String, 4 characters) node
#bundle (String, 4 characters) book
tfo-bject (Object) stdCtass
totems (Array, 1 element)
^formatter (String. 12 characters) text default

0 (Array, 1 element)
children (String, 0 characters)
theme hook, suggestions (Array, 4 elements)
label .hidden (Boolean) TRUE
label (NULL)
Items (Array, 1 element)

(Array. 1 element)

Hmarkup(Siring, 2 characters)29
field name^ css (String, 12 characters) ftetd-number
field type css {String, 4 characters) text
cJassesarray (Array, 4 elements)
Krumo version 0 . 2 . 1a | httptfkrurno.soufcefofge.net
Called from /hone/ben/cod/dgd7/drupal./sites/def ault/modules/dgd7glue/dgd7glue. nodule, line 53

. 3 0 .5 . , Krumo, kpr($vars); hook_


preprocess_field() , number

, ,
. , ,
, e lem ent; ,
, ite m s .

628

30. : 90 %

element .
Svarsl'itemsKO][^markup'] ( ;
). ,
, . ,
Svarsfelemenfl^items'ltOnsafevalue'] .
dgd7.org/225.

,
, ,
, ,
Compact .
30.6
Chapter 33 33 ( dgd7.org/other90), Appendix
( dgd7.org/render), Ch 33 (
dgd7.org/chapters).
3 0 .6 . hook_preprocess_field(),
Chapter [] Appendix []
Compact

/**
* h o o k _ p re p ro c e s s _ fie ld ().

*/
fu n c tio n d g d 7 g lu e _ p re p ro c e s s _ fie ld (& $ v a rs ) {
i f ($ v a rs ['e le m e n t' ] [ '# fie ld _ n a m e '] == 'fie ld _ n u m b e r'
&& $ v a r s ['e le m e n t'] [ '# b u n d le '] == 'b o o k ') {
$v = $ v a r s ['it e m s ' ] [ 0 ] [ '# m a rk u p '] ;
i f (is _ n u m e ric ($ v )) {
i f ($ v a r s ['e le m e n t' ] [ '#view _m ode'] == 'c o m p a c t') {
$v = t ( 'C h ! n ' j a r r a y ( '! n ' => $ v ),
a r r a y ( 'c o n t e x t ' => 'A b b re v ia tio n f o r C h a p te r ') ) ;

}
e ls e {
$v = t( 'C h a p te r I n ', a r r a y ( '! n ' => $ v ) ) ;

}
}
e ls e {
/ / , ,
i f ( $ v a r s ['e le m e n t' ] [ '#view _m ode'] == 'c o m p a c t') {
$v = t ( ' App ! n ', a r r a y ( '! n ' => $ v ),
a r r a y ( ' c o n te x t' => 'A b b re v ia tio n f o r A p p e n d ix ')) ;

}
e ls e {
$v = t('A p p e n d ix

I n ', a r r a y ( '! n ' => $ v ) ) ;

}
}
$ v a r s [ 'it e m s ']

[0][ '# m a rk u p ']

= $v;

>
}
,
.
, , .

Drupal.org Twitter

629

Drupal.org Twitter

8,
: Drupal.org, groups.drupal.org
Twitter.
, .
( ) . ,
.
, ,
Default, Plain text Trimmed.
Drupal-
api.drupal.org.
api.drupal.org Topics ap i.drupal.org/api/drupal/
groups/7, Field API
. Field API
(. 30.6).
Field API

Attach custom data fields to Drupal entities.

Field API bulk data deletion

Clean up after Field API bulk deletion operations.

Field Attach API

Operate on Field API data attached to Drupal


entities.

Field CRUD API

Create, update, and delete Field API fields, bundles,


and instances.

Field Info API

Obtain information about Field API configuration.

Field Language API

Handling of multilingual fields.

Fteld Storage API

Implement a storage engine for Field API data.

Field Types API

Define field types, widget types, display formatter


types, storage types.

. 30.6. ,

Field API api.drupal.org

, Field API, (
). Field
Types API: , ,
( ). ap i.d ru p a l.o rg /a p i/g ro u p /
field_types ( U R L -;
) ,
:
API Field :
. ()
( ).
field-type.
,
.
.
hook_f ield_formatter_info(), api.drupal.org/
hook_field_formatter_info .

, 30.7.

630

30. : 90 %

3 0 .7 . hook_field_formatter_info() dgd7glue.m odule

/**
* h o o k _ fie ld _ fo r m a tte r _ in fo ( ) .

*/
f u n c tio n d g d 7 g lu e _ fie ld _ fo r m a tte r _ in fo ( ) {
re tu rn a rra y (
'dgd 7g lu e_n um b er_a ccou nt_link' => a rra y (
'l a b e l ' => t( 'A c c o u n t l i n k ' ) ,
' f i e l d ty p e s ' => a r r a y ( ' n u m b e r_ in te g e r' ) ,

),

'd g d 7 g lu e _ te x t_ a c c o