A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. The service is made part of the client's state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern." Dependency injection is an advanced software design pattern and applying it will increase flexibility. Once you wrap your head around this pattern, you will be unstoppable.
A practical example of accessing services in objects using dependency injection
For the following example, let's assume we are creating a method that will use the service of A, we need to pull the dependencies of B and C into the plugin which we can use to inject whichever services we require.
- Application needs A so:
- Application gets A from the Container, so:
- Container creates C
- Container creates B and gives it C
- Container creates A and gives it B
- Application calls A
- A calls B
- B does something
Types of Dependency Injection
There are different types of Dependency Injection:
- Constructor injection
- Method injection
- Setter and property injection
- PHP callable injection
The DI container supports constructor injection with the help of type hints(Type hinting we can specify the expected data type) for constructor parameters. The type hints tell the container which classes or interfaces are dependent when it is used to create a new object. The container will try to get the instances of the dependent classes or interfaces and then inject them into the new object through the constructor.
In constructor injection we saw that the dependent class will use the same concrete class for its entire lifetime. Now if we need to pass separate concrete class on each invocation of the method, we have to pass the dependency in the method only.
Setter & Property Injection
Now we have discussed two scenarios where in constructor injection we knew that the dependent class will use one concrete class for the entire lifetime. The second approach is to use the method injection where we can pass the concrete class object in the action method itself. But what if the responsibility of selection of concrete class and invocation of method are in separate places. In such cases we need property injection.
PHP Callable Injection
Container will use a registered PHP callable to build new instances of a class. Each time when yii\di\Container::get() is called, the corresponding callable will be invoked. The callable is responsible to resolve the dependencies and inject them appropriately to the newly created objects
Dependency Injection: Advantages & Disadvantages
Reducing the dependency to each other of objects in application.
Unit testing is made easier.
Promotes re-usability of code or objects in different applications
Promotes logical abstraction of components.
DI increases complexity, usually by increasing the number of classes since responsibilities are separated more, which is not always beneficial.
Code will be coupled to the dependency injection framework.
It takes time to learn
If misunderstood it can lead to more harm than good
Dependency injection is a very simple concept of decoupling your code and easier to read. By injecting dependencies to objects we can isolate their purpose and easily swap them with others.
The service container is basically there to manage some classes. It keeps track of what a certain service needs before getting instantiated, does it for you and all you have to do is access the container to request that service. Using it the right way will save time and frustration, while Drupal developers will even make it easier for the layman.
admin Fri, 07/21/2017 - 07:43 Drupal developer Drupal Application Development
CiviCooP and Systopia and Palasthotel have been working together on CiviProxy and CiviProxy. This blog is a round up of what we have achieved in the last couple of days. The first thing we have achieved is that we had fun and a very good work atmosphere. We made long days and made lots of progress.
What are CiviProxy and CiviMcRestFace?
CiviProxy is a script to act as an application firewall for CiviCRM. It could be used to put your civicrm in secure network. CiviProxy is the gatekeeper to which external systems, such as your website, connect (this is for example when a user signs a petition on your website and the website submits this data to your CiviCRM). CiviProxy will make sure the call is from the right place (ip-adress) and is only doing what allowed to do.
CiviMcRestFace (CiviMRF) is a framework to be used in other systems (such as your external website) to connect to CiviCRM. The framework itself is divided in three parts: the abstract core (CMS/System independent), the core implementation (e.g. a Drupal 7 implementation), and lastly the module who is doing the actual submission (for example the cmrf_webform module which provides the functionality to submit a webform to CiviCRM).
What we have achieved:
- Completed the documentation on CiviProxy: https://docs.civicrm.org/civiproxy/en/latest
Got a working drupal 7 module with CiviMcRestFace:
- Completed screens for set up connection profiles (you can also provide the connection credentials through your module with an api; so that you can store them somewhere outside the database)
- Completed screen for the call log (a call is submission to CiviCRM through CiviMcRestFace)
- Added functionality to queue calls and run them in the background and added functionality to retry failed calls
- Added a basic webform integration module to submit a webform to the CiviCRM Api
- Added a rules integration module so that you can perform additional actions when a call succeeds or fails. Probably a use case is when a call fails you want to send the data by e-mail to the CiviCRM Administrator so that he or she can enter the data manually.
- Added an example module so you can see how you could use the cmrf_core module in your durpal projects
- Code: https://github.com/CiviMRF/cmrf_core/tree/7.x-dev
- Got a start with the drupal 8 module for CiviMcRestFace: https://github.com/CiviMRF/cmrf_core/tree/8.x-dev
Skip the Game vs Story and Entertainment vs Practical-Utility Traps: The Anatomy of Compelling Experiences - by Felipe Lara
This module provides integration between the aliyun SMS service and the SMS framework module.
"Candy is completely engineered to entice you to pick it up," says Gigantic lead concept artist Vinod Rams in a recent livestreamed chat about the game's design, development, and alluring art style. ...
Last weekend I had the pleasure of attending Drupal Camp Asheville 2017 ('twas my fourth year in a row : ). I absolutely love this event and encourage you to consider putting it on your list of Drupal events to hit next year. The Asheville area is a beautiful (and delicious) place to spend the weekend, but the bigger draw for me is the people involved:
(Check out all the pictures in the album on Flickr.)
Drupal Camp Asheville is always well organized (seriously, it's in the best of the best small conferences for venue, amenities, and content) and attended by a solid blend of seasoned Drupal users / contributors and newcomers. I live only an hour away, so I get to interact with my Drupal friends from Blue Oak Interactive, New Valley Media, and Kanopi on occasion, but then on Camp weekend I also get to see a regular mix of folks from Mediacurrent, Code Journeymen, Lullabot, Palantir, FFW, CivicActions, end users like NOAA, and more.
This year we got to hear from Adam Bergstein as the keynote speaker. Unfortunately, that "we" didn't include me at first, as I managed to roll up right after Adam spoke ... but his keynote is on YouTube already thanks to Kevin Thull! I encourage you to give it a listen to hear how Adam's experience learning to work against his own "winning strategy" as a developer (that of a honey badger ; ) helped him gain empathy for his fellow team members and find purpose in collaborative problem solving to make the world a better place.
I gave a presentation of Drupal Commerce 2.x focusing on how we've improved the out of the box experience since Commerce 1.x. This was fun to deliver, because we really have added quite a bit more functionality along with a better customer experience in the core of Commerce 2.x itself. These improvements continued all the way up to our first release candidate tagged earlier this month, which included new promotions, coupons, and payment capabilities.
Many folks were surprised by how far along Commerce 2.x is, but now that Bojan has decompressed from the RC1 sprint, I expect we'll start to share more about the new goodies on the Drupal Commerce blog. (If you're so inclined, you can subscribe to our newsletter to get bi-weekly news / updates as well.)
Lastly, I loved just hanging out and catching up with friends at the venue and at the afterparty. I played several rounds of a very fun competitive card game in development by Ken Rickard (follow him to find out when his Kickstarter launches!). I also enjoyed several rounds of pool with other Drupallers in the evening and closed out the night with cocktails at Imperial Life, one of my favorite cocktail bars in Asheville. I treasure these kinds of social interactions with people I otherwise only see as usernames and Twitter handles online.
Can't wait to do it again next year!
As a Belgian sports fan, I will always be a loyal to the Belgium National Football Team. However, I am willing to extend my allegiance to Arsenal F.C. because they recently launched their new site in Drupal 8! As one of the most successful teams of England's Premier League, Arsenal has been lacing up for over 130 years. On the new Drupal 8 site, Arsenal fans can access news, club history, ticket services, and live match results. This is also a great example of collaboration with two Drupal companies working together - Inviqa in the U.K. and Phase2 in the US If you want to see Drupal 8 on Arsenal's roster, check out https://www.arsenal.com!
As a Belgian sports fan, I will always be a loyal to the Belgium National Football Team. However, I am willing to extend my allegiance to Arsenal F.C. because they recently launched their new site in Drupal 8! As one of the most successful teams of England's Premier League, Arsenal has been lacing up for over 130 years. On the new Drupal 8 site, Arsenal fans can access news, club history, ticket services, and live match results. This is also a great example of collaboration with two Drupal companies working together - Inviqa in the UK and Phase2 in the US. If you want to see Drupal 8 on Arsenal's roster, check out https://www.arsenal.com!
When dealing with a site migration that has hundreds of thousands of nodes with larger than usual field values, you might notice some performance issues.
In one instance recently I had to write a migration for nodes that had multiple fields of huge JSON strings and parse them. The migration itself was solid, but I kept running into memory usage warnings that would stop the migration its tracks.
Sometime during the migration, I would see these messages:
Creating a Modular, Interactive Learning Tool on Drupal 8Highlights
- A media-rich, modular template built on Drupal 8
- Innovative feature components to create context with a variety of content
- Expansion of existing brand elements to create cohesive but unique identities
We want to make your project a success.Let's Chat. Our Client
The Fine Arts Museums of San Francisco (FAMSF) is the largest public arts institution in the city of San Francisco and one of the largest art museums in the state of California. With an annual combined attendance of 1,442,200 people for the two museums (the Legion of Honor and the de Young), FAMSF sought a way to expand the experience for attendees beyond the reach of the physical exhibits themselves and to deepen visitors’ engagement with the art. From this goal, the idea of ‘Digital Stories’ was born.The Challenge of ‘Digital Stories’
FAMSF had an interesting challenge:
- They wanted to create engaging, interactive websites for each future exhibition.
- They wanted each exhibit website to be unique – not employing the same template over and over.
- They wanted these websites to serve as educational tools for their exhibits over the course of many years.
- They required a platform that museum staff could use to author without starting from scratch.
- They needed to create these website for their two museums — the Legion of Honor and the de Young — with different branding appropriate to each museum and to their respective exhibitions.
In short, they required a tool that allowed them to “spin up” unique, interactive educational microsites for multiple exhibits, across two museums, for several years.
The problem also required more than a front-end solution to create the interactions. It needed to be built on a content management system — Drupal 8 in this case — that could support their content editors, providing them with a tool where they could simply upload and arrange content to produce amazing, dynamic exhibit sites.The Solution Understanding the brands
In order to create an adaptable template for the museums, we needed to first understand the two brands. The Legion of Honor displays a European collection that spans ancient cultures to early modernism.. The exhibits are seen as authoritative manifestos. The de Young, on the other hand, houses diverse collections including works from Africa, Oceania, Mesoamerica, and American Art. The exhibits are challenging and exploratory, and invite visitors to think about art in new and different ways. The framework for the microsites needed to be flexible enough to convey either brand effectively.Understanding the content
The FAMSF project was unique in that it wasn’t the typical content strategy we do for websites. Because this project was more interaction and feature driven, our content strategy was focused on the different elements of the stories to be told, and how we could showcase those elements to create an expansive experience for visitors. For example, users should be able to zoom in on a painting to get a closer look, or be able to click on a question and see the answer display.Creating the right interactive features
With so many different possible elements, it was important to narrow down the interactions and feature components that they needed. These components needed to match their content and also have the ability to be executed in a tight timeline.
For overall presentation treatment, we introduced a flexible content area where individual sections could be introduced as revealable “card sections”. Within each card section, a site administrator can first choose to add hero content for that section which could include either background images or background video, plus various options for placement and style of animated headers.
Next within the card section, a series of “Section Layout Components” were available, such as single column or two columns side-by-side that they could choose from. Within the column sections they could place modular content components that included media (video, images, audio) and text.Menu features for the Early Monet site, one of the Digital Stories for the Legion of Honor Museum.
Many interactive components went through a process of discovery and iteration achieved through team collaboration, taking into account the strategic needs of each component to increase user engagement, along with content requirements of the component, look, feel and interactivity. Components as well as the general treatment were presented as proof-of-concept, where additional client feedback was taken into account. Most interactivity on individual components was done by creating custom jQuery behaviors and CSS3 animation for each component. This often included animated transitional effects to help reveal more pieces of content as users look more closely.Collapsible content displayed on the “Summer of Love” site, one of the Digital Stories for the de Young MuseumApplying the FAMSF brand to design components
Although the same colors and typefaces employed in FAMSF’s main website were used, it was agreed from the beginning that the Digital Stories and the main website were going to be “cousins” within the same family as opposed to “siblings,” so they could definitely have their own unique feel. This supported the goal of designing the microsites to be an immersive and very targeted experience. This was achieved by expanding upon the existing color palette and using additional fonts within the brand’s font family.Style tile created for the de Young: playful / challenging / contemporary / exploratoryThe de Young style tile creates a sense of excitement and delight through the use of whimsical icons and graphics. Easily recognizable iconography is incorporated in order to communicate effectively with a wide audience, with the added bonus of fun details such as saturated drop shadows and stripes.
In order to make sure the FAMSF team could reliably reproduce new, unique exhibit sites without having to change any code, we had to systematize the structure of the content and application of the interactions.
The Digital Story Content type for each exhibition had modular and reusable interactive features including the following:
- An image comparison component for comparing two or three images side by side, where revealable text can give more context for each image
- An audio component for uploading audio files that included custom playback buttons and a revealable transcript
- The ability to add a highly customizable caption or credit to any instance of an image or video
- A zoomable image component where markers can be positioned on the initial image and that marker can be clicked, revealing a more detailed image and an area for more commentary on that detail
- A revealable “read more” section that can contain further subsections
- An image with an overlay, to be able to reveal a new image on top of the existing image. This was used to demonstrate aspects of the composition of a painting, showing a drawing on top of the painting.
- A video component that could support uploaded videos or embedded streaming video
- A horizontal slider that could contain images and captions with a variety of configuration
- A stand-alone quotation with display type and an animated transition
The resulting platform we built allowed FAMSF to launch two exhibit sites in rather quick succession, which would have been incredibly difficult if they had to build each from scratch. In a matter of weeks, FAMSF launched two quite different interactive learning experiences:
Both exhibit sites have received praise, not only internally at FAMSF, but from online reviews of the exhibits, which mention the accompanying Digital Stories online learning tool.
Since the completion of the engagement with Palantir, FAMSF has already leveraged this tool to create an additional Digital Stories site (digitalstories.famsf.org/degas), and they have plans to create at least three more before the end of the year. Because of the simplicity of using the platform, they anticipate being able to spin up 4 - 5 different exhibit sites per year.
Current success for the Digital Stories sites is being measured by individual views and actual participation rate, and the initial results are on track with FAMSF’s initial goals:
- The Monet site has over 30,000 views
- The Summer of Love site has just under 30,000 views
- Visitors are typically spending 4 - 5 minutes on each page
We’re pleased to have been part of a project that helps expand visitors’ understanding of important artists and their works. FAMSF was a great partner, allowing for a true collaboration focused on both pairing the nest technologies to fit the material and also providing the best learning mechanism for those engaging with the content.
We want to make your project a success.Let's Chat. Drupal 8 digitalstories.famsf.org/summer-of-love digitalstories.famsf.org/early-monet/
IMCE Copy Link adds a Copy Link button to the IMCE file manager tabs. Clicking it copies the currently selected file URL to the clipboard. The URL can then be pasted into any drupal text field or an external program.
When no file is selected, the current directory URL is copied.
Without this module, this operation can only be performed using a particularly lengthy workaround involving the imce_wysiwyg module.