#Notes from Drupalcon Portland, Wednesday May 22, 2013
##General Drupal
##The Old And The New Field API In Drupal8
- Field config and instances written to yaml files, do not need features to deploy
- Field definitions missing
widget
anddisplay
- "Don't hack core." replaced by "Don't hack your active config." - Alex Pott
- Instead import from development/staging into active if you edit config by hand
- Sometimes it may work and for other configs it will probably work, but in the case of Field API your stored data can be impacted by a config change
- Field API uses Entity API,
$field = entity_create('field_entity', array(...));
,$field->save();
,entity_create('field_instance', array(...))->save();
- Still a lot about this API is up in the air / to be determined. Slides are confusing as the examples are out of context
- Symfony2/Doctrine style Annotations replace
hook_field_info()
- Field widgets exist as plugin clases that extend
WidgetBase
, makes sense - Field formatters work the same way, extending
FormatBase
- Field types are currently in progress
- Every entity property on an entity is a "field"
- Base fields
$node->nid
$node->title
$node->uuid
- Configurable fields
$node->body
$user->field_custom...
- Field values are objects
$node->field_tags instanceof FieldInterface
$node->field_tags[0] instance of FieldItemInterface
- Computed fields
FieldNewValue
computes on access, something like$comment->is_new->value;
- Do not have to use language constants. Just get
$node->body->value
or$node->body[0]->value
- Translation accessible through helper,
$trans = $node->getTranslation('de');
$node instance of NodeInterface
$trans instanceof Nodeinterface
- [WIP]
- Translation accessible through helper,
- Entity validation decoupled from form validation
- Builds on Symfony2 validator
- Constraints are discoverable through Drupal 8 plugin system
- Hidden form field included in core. It is not a
hidden
input type. What? - Placeholders are available for applicable field types
- Multiple upload property for file and image fields.
- Drag and drop files and images is a work in progress
- User picture is a field
- More granular permissions on Field UI
##Make Drupal The Best REST Server For Single Page Apps
- Backend developer becoming more concerned with building backend apis, a lot of application logic moved to the front end.
- nodejs + express approach = "Here's your interface, what would you like to pass through it?"
- Pull data from multiple sources
- Drupal
- Assumes your data is in one place
- Drupal (web services) HAL nests dependent resources (node references)
- Incomplete, not finished implementing Files and Users
- URIs not usable by the client
- REST things that would be nice
- Batch/Queue: Support HTTP 202 (Accepted) and POST callback
- Drupal needs better caching
- Entities to define their own caching structures
- Varnish vcl for Drupal 8 would be helpful
- No reason links to resources in the JSON needs to point back to the same service.
- Link to service at another port and get back JSON
##REST For Web Developers
- Allow PUT to create resource when client is allowed to set the uri, new records should probably come through POST
- HTTP Status Codes
- 204 when resource successfully deleted
- 4** when the client did something wrong
- Can set preference for encoding in HTTP header using
q
parameter - Authorization token as header instead of in body
- Prefix any "invented" headers with
X-
- Always set Content-Type when returning data
- Hypermedia are hyperlinks for APIs
- Clients can find related data
- Relying on following links means URLs can change
- Returning ids instead of uris can lead to people concatenating their own urls and getting them wrong.
- GET to retrieve a record before you PUT to update it.
- PUT with an incomplete record should reject the resource unless you want your logic to allow optional fields
- PATCH is like doing a diff. Supposed to be used to update a small part of a resource instead of PUT which deals with the entire resource
- Response from PATCH contains the full resource, not just the updated field
- OAuth
- Handles the relationship between
- user
- user's data stored on a provider
- consumer wanting to access user's data
- Tokens are easily revoked for each service without needing to update other consuming services
- Use OAuth2 over HTTPS
- Handles the relationship between
- When to use REST
- Data driven applications
- Where REST is (or can be) understood
- Consider the failure case
- Split data into subresources
- Allow more/less verbose representations
##Managing Drupal And Subsites with Puppet
- Infrastucture as code: executable documentation
- Code is meant to be legible
- Everyone using VM has the same environment.
- Can spin up local environment similar to eventual production env
- Declarative model: describe the state you want
- You shouldn't think of coding Puppet as if you were writing a shell script. Just tell Puppet what you need done and let it happen.
- Puppet Resources
- Unit of configuration, combine to make large components
- Model the expected state of your system
- Resource abstraction layer
- Shouldn't need to know the package manager in use. Package will use apt, yum, etc on it's own depending on system
- Modules are containers for configuration
- hierarchy convention that enabes:
- auto-loading of classes
- file serving for templates/files
- auto-delivery of extensions
- easy sharing (Puppetforge)
- hierarchy convention that enabes:
- Multiple clsses are declared together to represent a "node"
- Some resources
- http://docs.puppetlabs.com/learning/
- http://puppetlabs.com/training
- http://groups.google.com/group/puppet-users
- IRC: #puppet
- http://forge.puppetlabs.com/binford2k/drupal: Drupal Puppet module to manage full stack
- Managing Drupal with Puppet
- Drupal install consists of:
- web server
- database
- packages: services, php, extensions, drupal, drush
- configuration: docroot, settings.php, php.ini, sites/*
- Keep core and module versions consistant
- Manage modules (install, enable, disable, update*) through Puppet manifest
- Currently with
binford2k/drupal
, you cannotensure => latest
on Drupal modules, but if you change the version specified then it can potentially update - If you disable a module in Drupal, you will want to remove
ensure => enabled
as well or the next time the Puppet agent runs, it will enabled it.
- Currently with
- Drupal install consists of: