From 4f623592f963b65461e67f8e2b40b114f8833d4b Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 23 Aug 2018 12:23:20 +0100 Subject: [PATCH] wip --- ...amples-of-laravel-collections-in-drupal.md | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 source/_posts/2018-08-23-examples-of-laravel-collections-in-drupal.md diff --git a/source/_posts/2018-08-23-examples-of-laravel-collections-in-drupal.md b/source/_posts/2018-08-23-examples-of-laravel-collections-in-drupal.md new file mode 100644 index 00000000..cca85315 --- /dev/null +++ b/source/_posts/2018-08-23-examples-of-laravel-collections-in-drupal.md @@ -0,0 +1,63 @@ +--- +title: Examples of using Laravel Collections in Drupal +tags: + - drupal + - drupal-7 + - drupal-8 + - drupal-planet + - laravel + - laravel-collections + - php +has_tweets: true +--- +{% block excerpt %} +Since starting to work with Laravel as well as Drupal and Symfony, watching Adam Wathan’s [Refactoring to Collections][0] course as well as [lessons on Laracasts][6], I’ve become a fan of [Laravel’s Illuminate Collections][1] and the object-orientated pipeline approach for interacting with PHP arrays. + +In fact I’ve given a talk on [using Collections outside Laravel][2] and have written a [Collection class module][3] for Drupal 7. + +I’ve also tweeted several examples of code that I’ve written within Drupal that use Collections, and I thought it would be good to collate them all here for reference. +{% endblock %} + +{% block content %} +Thanks again to [Tighten][4] for releasing and maintaining the [tightenco/collect library][5] that makes it possible to pull in Collections via Composer. + +
+ {% include 'tweet' with { + class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0', + data_cards: true, + content: '

Putting @laravelphp's Collection class to good use, cleaning up some of my @drupal 8 code. Thanks @TightenCo for the Collect library! pic.twitter.com/Bn1UfudGvp

— Oliver Davies (@opdavies) August 18, 2017', + } %} + + {% include 'tweet' with { + class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0', + data_cards: true, + content: '

Putting more @laravelphp Collections to work in my @drupal code today. 😁 pic.twitter.com/H8xDTT063X

— Oliver Davies (@opdavies) February 14, 2018', + } %} + + {% include 'tweet' with { + class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0', + data_cards: true, + content: '

I knew that you could specify a property like 'price' in Twig and it would also look for methods like 'getPrice()', but I didn't know (or had maybe forgotten) that @laravelphp Collections does it too.

This means that these two Collections return the same result.

Nice! 😎 pic.twitter.com/2g2IfThzdy

— Oliver Davies (@opdavies) June 20, 2018', + } %} + + {% include 'tweet' with { + class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0', + data_cards: true, + content: '

More @laravelphp Collection goodness, within my #Drupal8 project! pic.twitter.com/mWgpNbNIrh

— Oliver Davies (@opdavies) August 10, 2018', + } %} + + {% include 'tweet' with { + class: 'block mb-4 lg:w-1/2 lg:px-2 lg:mb-0', + data_cards: true, + content: '

Some more #Drupal 8 fun with Laravel Collections. Loading the tags for a post and generating a formatted string of tweetable hashtags. pic.twitter.com/GbyiRPzIRo

— Oliver Davies (@opdavies) August 23, 2018', + } %} +
+{% endblock %} + +[0]: https://adamwathan.me/refactoring-to-collections +[1]: https://laravel.com/docs/collections +[2]: /talks/using-laravel-collections-outside-laravel +[3]: https://www.drupal.org/project/collection_class +[4]: https://tighten.co +[5]: https://packagist.org/packages/tightenco/collect +[6]: https://laracasts.com/series/how-do-i/episodes/18